aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2010-07-20 12:30:38 -0700
committerDan Williams <dcbw@redhat.com>2010-07-20 12:30:38 -0700
commitd18fbaa1c73a88b6f36437fbf712134c8aad5238 (patch)
tree5a38f6b8eb35ee5c05fa6fbb7a737103c607c100 /src
parente239bf15bb9787d15c429824b1e1176c35e978b6 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/mm-charsets.c14
-rw-r--r--src/mm-generic-gsm.c22
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;
}