gsm: ensure invalid operator names don't get used (rh #597088)
Apparently g_convert() can still return garbage that's not valid in the character set you're converting to (???). But even if we don't need to convert the operator name, make sure it's valid UTF-8 before we go shoving it through D-Bus.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user