From 2af3c733b7a31d755d7dec5b59113b9c73209d16 Mon Sep 17 00:00:00 2001 From: Tommi Kenakkala Date: Fri, 13 Feb 2015 17:50:16 +0200 Subject: sms: Fix alphanumeric TP-OA handling TP-OA max length comparisons were incorrect because TP-OA's 7-bit coded octets transport eleven 8-bit chars. The current code assumed only 10 chars were possible. The patch - increases the array size to 23, (maximum of 22 bytes for UTF8 encoding + null terminator) - Updates the sanity check to account for the correct maximum - For encoding, checks the maximum length in UTF8 characters instead of bytes --- src/smsutil.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/smsutil.c') diff --git a/src/smsutil.c b/src/smsutil.c index be60ee95..74afb651 100644 --- a/src/smsutil.c +++ b/src/smsutil.c @@ -524,7 +524,8 @@ static gboolean encode_validity_period(const struct sms_validity_period *vp, gboolean sms_encode_address_field(const struct sms_address *in, gboolean sc, unsigned char *pdu, int *offset) { - size_t len = strlen(in->address); + const char *addr = (const char *)&in->address; + size_t len = strlen(addr); unsigned char addr_len = 0; unsigned char p[10]; @@ -546,7 +547,8 @@ gboolean sms_encode_address_field(const struct sms_address *in, gboolean sc, unsigned char *gsm; unsigned char *r; - if (len > 11) + /* TP-OA's 10 octets transport 11 8-bit chars */ + if (g_utf8_strlen(addr, strlen(addr)) > 11) return FALSE; gsm = convert_utf8_to_gsm(in->address, len, NULL, &written, 0); @@ -675,7 +677,11 @@ gboolean sms_decode_address_field(const unsigned char *pdu, int len, if (utf8 == NULL) return FALSE; - if (strlen(utf8) > 20) { + /* + * TP-OA's 10 octets transport 11 8-bit chars, + * 22 bytes+terminator in UTF-8. + */ + if (strlen(utf8) > 22) { g_free(utf8); return FALSE; } -- cgit v1.2.3