aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan Williams <njw@chromium.org>2011-09-23 17:21:15 -0400
committerDan Williams <dcbw@redhat.com>2011-09-27 13:16:08 -0500
commit00670456ffb4b08af3620a95c73601bc15d84eb9 (patch)
tree94e2364d4fd29fe8224d056b0deb007e18b37908 /src
parent18fc92ef7304d01c5ec11ced22ff82c4ab6dbbe1 (diff)
sms: sanitize 8-bit data so that it is UTF8-clean
When receiving a SMS message with raw 8-bit data, sanitize it by replacing non-ASCII characters with \xNN escape sequences. This prevents a problem further down the line where the body of the message is passed into DBus as a string, and DBus requires strings to be UTF-8. BUG=chrome-os-partner:5953 TEST=Run network_ModemManagerSMS.py with the PDU from this bug. Change-Id: Ic33a365f9a065c49a325e047e4c3f5e81450fa1f Reviewed-on: http://gerrit.chromium.org/gerrit/8232 Reviewed-by: Eric Shienbrood <ers@chromium.org> Tested-by: Nathan J. Williams <njw@chromium.org> Commit-Ready: Nathan J. Williams <njw@chromium.org>
Diffstat (limited to 'src')
-rw-r--r--src/mm-sms-utils.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/mm-sms-utils.c b/src/mm-sms-utils.c
index 3f56a644..1b32a796 100644
--- a/src/mm-sms-utils.c
+++ b/src/mm-sms-utils.c
@@ -13,6 +13,9 @@
* Copyright (C) 2011 Red Hat, Inc.
*/
+#include <ctype.h>
+#include <stdio.h>
+
#include <glib.h>
#include "mm-charsets.h"
@@ -200,8 +203,22 @@ sms_decode_text (const guint8 *text, int len, SmsEncoding encoding, int bit_offs
g_free (unpacked);
} else if (encoding == MM_SMS_ENCODING_UCS2)
utf8 = g_convert ((char *) text, len, "UTF8", "UCS-2BE", NULL, NULL, NULL);
- else if (encoding == MM_SMS_ENCODING_8BIT)
- utf8 = g_strndup ((const char *)text, len);
+ else if (encoding == MM_SMS_ENCODING_8BIT) {
+ /* DBus requires UTF-8 strings, so we have some sanitizing to do */
+ char *p;
+ int i;
+ utf8 = g_malloc0 (4*len+1); /* Worst case: Every byte becomes "\xFF" */
+ p = utf8;
+ for (i = 0 ; i < len ; i++) {
+ if (isascii (text[i]) && text[i] != '\0')
+ *p++ = text[i];
+ else {
+ sprintf(p, "\\x%02x", text[i]);
+ p += 4;
+ }
+ }
+ *p = '\0';
+ }
else
utf8 = g_strdup ("");