diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mm-charsets.c | 14 | ||||
-rw-r--r-- | src/mm-generic-gsm.c | 22 |
2 files changed, 28 insertions, 8 deletions
diff --git a/src/mm-charsets.c b/src/mm-charsets.c index c75c3a97..e61e56ea 100644 --- a/src/mm-charsets.c +++ b/src/mm-charsets.c @@ -154,9 +154,10 @@ mm_modem_charset_byte_array_append (GByteArray *array, char * mm_modem_charset_hex_to_utf8 (const char *src, MMModemCharset charset) { - char *unconverted; + char *unconverted, *converted; const char *iconv_from; gsize unconverted_len = 0; + GError *error = NULL; g_return_val_if_fail (src != NULL, NULL); g_return_val_if_fail (charset != MM_MODEM_CHARSET_UNKNOWN, NULL); @@ -170,6 +171,15 @@ mm_modem_charset_hex_to_utf8 (const char *src, MMModemCharset charset) if (charset == MM_MODEM_CHARSET_UTF8 || charset == MM_MODEM_CHARSET_IRA) return unconverted; - return g_convert (unconverted, unconverted_len, "UTF-8//TRANSLIT", iconv_from, NULL, NULL, NULL); + converted = g_convert (unconverted, unconverted_len, + "UTF-8//TRANSLIT", iconv_from, + NULL, NULL, &error); + if (!converted || error) { + g_clear_error (&error); + g_free (unconverted); + converted = NULL; + } + + return converted; } diff --git a/src/mm-generic-gsm.c b/src/mm-generic-gsm.c index 2154ca91..3edb6e38 100644 --- a/src/mm-generic-gsm.c +++ b/src/mm-generic-gsm.c @@ -1766,12 +1766,22 @@ parse_operator (const char *reply, MMModemCharset cur_charset) g_regex_unref (r); } - /* Some modems (Option & HSO) return the operator name as a hexadecimal - * string of the bytes of the operator name as encoded by the current - * character set. - */ - if (operator && (cur_charset == MM_MODEM_CHARSET_UCS2)) - convert_operator_from_ucs2 (&operator); + if (operator) { + /* Some modems (Option & HSO) return the operator name as a hexadecimal + * string of the bytes of the operator name as encoded by the current + * character set. + */ + if (cur_charset == MM_MODEM_CHARSET_UCS2) + convert_operator_from_ucs2 (&operator); + + /* Ensure the operator name is valid UTF-8 so that we can send it + * through D-Bus and such. + */ + if (!g_utf8_validate (operator, -1, NULL)) { + g_free (operator); + operator = NULL; + } + } return operator; } |