ifxmodem: Handle malformed emergency numbers

This might be either a modem firmware bug or the SIM card is provisioned
really badly, but the last entry contains garbage characters.

ofonod[20620]: Voice: < \r\n+XLEMA: 1,9,"112",,1\r\n\r\n+XLEMA: 2,9,"911",,1\r\n\r\n+XLEMA: 3,9,"000",57,1\r\n\r\n+XLEMA: 4,9,"08",49,1\r\n\r\n+XLEMA: 5,9,"112",49,1\r\n\r\n+XLEMA: 6,9,"118",0,1\r\n\r\n+XLEMA: 7,9,"119",0,1\r\n\r\n+XLEMA: 8,9,"911",0,1\r\n\r\n+XLEMA: 9,9,"999\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377",0,1\r\n

Fix this by just validating the string and cutting off once an invalid
character is found.
This commit is contained in:
Marcel Holtmann 2012-02-10 02:15:16 +01:00
parent b1b0fe761e
commit cfdc96186e
1 changed files with 14 additions and 4 deletions

View File

@ -794,7 +794,7 @@ static void xlema_notify(GAtResult *result, gpointer user_data)
struct voicecall_data *vd = ofono_voicecall_get_data(vc);
GAtResultIter iter;
int index, total_cnt;
const char *number;
const char *number, *end;
int count = (vd->en_list == NULL) ? 0 : g_strv_length(vd->en_list);
g_at_result_iter_init(&iter, result);
@ -814,7 +814,12 @@ static void xlema_notify(GAtResult *result, gpointer user_data)
if (vd->en_list == NULL)
vd->en_list = g_new0(char *, total_cnt + 1);
vd->en_list[count] = g_strdup(number);
if (g_utf8_validate(number, -1, &end) == FALSE) {
vd->en_list[count] = g_strndup(number, end - number);
ofono_warn("Malformed emergency number: %s",
vd->en_list[count]);
} else
vd->en_list[count] = g_strdup(number);
if (index != total_cnt)
return;
@ -832,7 +837,7 @@ static void xlema_read(gboolean ok, GAtResult *result, gpointer user_data)
GAtResultIter iter;
int num = 0;
int index, total_cnt;
const char *number;
const char *number, *end;
if (!ok) {
DBG("Emergency number list read failed");
@ -859,7 +864,12 @@ static void xlema_read(gboolean ok, GAtResult *result, gpointer user_data)
if (!g_at_result_iter_next_string(&iter, &number))
continue;
vd->en_list[num++] = g_strdup(number);
if (g_utf8_validate(number, -1, &end) == FALSE) {
vd->en_list[num] = g_strndup(number, end - number);
ofono_warn("Malformed emergency number: %s",
vd->en_list[num++]);
} else
vd->en_list[num++] = g_strdup(number);
}
ofono_voicecall_en_list_notify(vc, vd->en_list);