summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiří Klimeš <jklimes@redhat.com>2012-11-27 10:48:48 +0100
committerJiří Klimeš <jklimes@redhat.com>2012-11-27 13:25:25 +0100
commite97b229e663dcd6d24a15fef51f13e2886ddf134 (patch)
tree2545eb45d20269a62613e062d14803d06bebb494
parente6052a4abfde3550b0b9c2229adb0bb381ac4a06 (diff)
core: fix possible crash in g_utf8_validate()
We can skip additional UTF-8 validity check when parsing operator. mm_charset_take_and_convert_to_utf8() already does a UTF-8 validity check internally before returning the string, so it's pointless to do a new one on the returned string. Plus, mm_charset_take_and_convert_to_utf8() may really return NULL, which would end up in segfaulting as g_utf8_validate() expects always a non-NULL string. Based on 219424a6e2d017491a05ecbed661bccde3f991ef (MM_06 branch)
-rw-r--r--src/mm-modem-helpers.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index 8cf9a29f..928fa6f3 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -1511,13 +1511,14 @@ mm_3gpp_parse_operator (const gchar *reply,
1511 * string of the bytes of the operator name as encoded by the current 1511 * string of the bytes of the operator name as encoded by the current
1512 * character set. 1512 * character set.
1513 */ 1513 */
1514 if (cur_charset == MM_MODEM_CHARSET_UCS2) 1514 if (cur_charset == MM_MODEM_CHARSET_UCS2) {
1515 /* In this case we're already checking UTF-8 validity */
1515 operator = mm_charset_take_and_convert_to_utf8 (operator, MM_MODEM_CHARSET_UCS2); 1516 operator = mm_charset_take_and_convert_to_utf8 (operator, MM_MODEM_CHARSET_UCS2);
1516 1517 }
1517 /* Ensure the operator name is valid UTF-8 so that we can send it 1518 /* Ensure the operator name is valid UTF-8 so that we can send it
1518 * through D-Bus and such. 1519 * through D-Bus and such.
1519 */ 1520 */
1520 if (!g_utf8_validate (operator, -1, NULL)) { 1521 else if (!g_utf8_validate (operator, -1, NULL)) {
1521 g_free (operator); 1522 g_free (operator);
1522 return NULL; 1523 return NULL;
1523 } 1524 }
@@ -1525,7 +1526,7 @@ mm_3gpp_parse_operator (const gchar *reply,
1525 /* Some modems (Novatel LTE) return the operator name as "Unknown" when 1526 /* Some modems (Novatel LTE) return the operator name as "Unknown" when
1526 * it fails to obtain the operator name. Return NULL in such case. 1527 * it fails to obtain the operator name. Return NULL in such case.
1527 */ 1528 */
1528 if (g_ascii_strcasecmp (operator, "unknown") == 0) { 1529 if (operator && g_ascii_strcasecmp (operator, "unknown") == 0) {
1529 g_free (operator); 1530 g_free (operator);
1530 return NULL; 1531 return NULL;
1531 } 1532 }