aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mm-base-sim.c23
-rw-r--r--src/mm-broadband-modem-mbim.c9
-rw-r--r--src/mm-charsets.c21
-rw-r--r--src/mm-charsets.h5
-rw-r--r--src/mm-sms-part-3gpp.c18
-rw-r--r--src/tests/test-charsets.c6
6 files changed, 48 insertions, 34 deletions
diff --git a/src/mm-base-sim.c b/src/mm-base-sim.c
index f50af820..c8bd32d4 100644
--- a/src/mm-base-sim.c
+++ b/src/mm-base-sim.c
@@ -1412,22 +1412,31 @@ parse_spn (const gchar *response,
(sw1 == 0x91) ||
(sw1 == 0x92) ||
(sw1 == 0x9f)) {
- gsize buflen = 0;
- g_autofree guint8 *bin = NULL;
+ g_autoptr(GByteArray) bin_array = NULL;
+ g_autofree guint8 *bin = NULL;
+ gsize binlen = 0;
/* Convert hex string to binary */
- bin = mm_utils_hexstr2bin (hex, -1, &buflen, error);
+ bin = mm_utils_hexstr2bin (hex, -1, &binlen, error);
if (!bin) {
g_prefix_error (error, "SIM returned malformed response '%s': ", hex);
return NULL;
}
/* Remove the FF filler at the end */
- while (buflen > 1 && bin[buflen - 1] == 0xff)
- buflen--;
+ while (binlen > 1 && bin[binlen - 1] == 0xff)
+ binlen--;
+ if (binlen <= 1) {
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
+ "SIM returned empty response '%s'", hex);
+ return NULL;
+ }
+ /* Setup as bytearray.
+ * First byte is metadata; remainder is GSM-7 unpacked into octets; convert to UTF8 */
+ bin_array = g_byte_array_sized_new (binlen - 1);
+ g_byte_array_append (bin_array, bin + 1, binlen - 1);
- /* First byte is metadata; remainder is GSM-7 unpacked into octets; convert to UTF8 */
- return (gchar *)mm_charset_gsm_unpacked_to_utf8 (bin + 1, buflen - 1, FALSE, error);
+ return mm_modem_charset_bytearray_to_utf8 (bin_array, MM_MODEM_CHARSET_GSM, FALSE, error);
}
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
diff --git a/src/mm-broadband-modem-mbim.c b/src/mm-broadband-modem-mbim.c
index 5168b0e1..dc199d5d 100644
--- a/src/mm-broadband-modem-mbim.c
+++ b/src/mm-broadband-modem-mbim.c
@@ -4809,11 +4809,14 @@ ussd_decode (guint32 scheme,
gchar *decoded = NULL;
if (scheme == MM_MODEM_GSM_USSD_SCHEME_7BIT) {
- g_autofree guint8 *unpacked = NULL;
- guint32 unpacked_len;
+ g_autoptr(GByteArray) unpacked_array = NULL;
+ guint8 *unpacked = NULL;
+ guint32 unpacked_len;
unpacked = mm_charset_gsm_unpack ((const guint8 *)data->data, (data->len * 8) / 7, 0, &unpacked_len);
- decoded = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len, FALSE, error);
+ unpacked_array = g_byte_array_new_take (unpacked, unpacked_len);
+
+ decoded = mm_modem_charset_bytearray_to_utf8 (unpacked_array, MM_MODEM_CHARSET_GSM, FALSE, error);
if (!decoded)
g_prefix_error (error, "Error decoding USSD command in 0x%04x scheme (GSM7 charset): ", scheme);
} else if (scheme == MM_MODEM_GSM_USSD_SCHEME_UCS2) {
diff --git a/src/mm-charsets.c b/src/mm-charsets.c
index b0f4ea60..93e60e10 100644
--- a/src/mm-charsets.c
+++ b/src/mm-charsets.c
@@ -343,11 +343,11 @@ utf8_to_gsm_ext_char (const gchar *utf8,
return FALSE;
}
-guint8 *
-mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm,
- guint32 len,
- gboolean translit,
- GError **error)
+static guint8 *
+charset_gsm_unpacked_to_utf8 (const guint8 *gsm,
+ guint32 len,
+ gboolean translit,
+ GError **error)
{
g_autoptr(GByteArray) utf8 = NULL;
guint i;
@@ -744,7 +744,8 @@ mm_charset_take_and_convert_to_utf8 (gchar *str,
break;
case MM_MODEM_CHARSET_GSM:
- utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 ((const guint8 *) str, strlen (str), FALSE, NULL);
+ /* This is WRONG! GSM may have embedded NULs (character @)! */
+ utf8 = (gchar *) charset_gsm_unpacked_to_utf8 ((const guint8 *) str, strlen (str), FALSE, NULL);
g_free (str);
break;
@@ -1111,10 +1112,10 @@ mm_modem_charset_bytearray_to_utf8 (GByteArray *bytearray,
switch (charset) {
case MM_MODEM_CHARSET_GSM:
- utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 (bytearray->data,
- bytearray->len,
- translit,
- error);
+ utf8 = (gchar *) charset_gsm_unpacked_to_utf8 (bytearray->data,
+ bytearray->len,
+ translit,
+ error);
break;
case MM_MODEM_CHARSET_IRA:
case MM_MODEM_CHARSET_UTF8:
diff --git a/src/mm-charsets.h b/src/mm-charsets.h
index 8300ad6c..9f2ac7e8 100644
--- a/src/mm-charsets.h
+++ b/src/mm-charsets.h
@@ -48,11 +48,6 @@ gchar *mm_modem_charset_byte_array_to_utf8 (GByteArray *array,
gchar *mm_modem_charset_hex_to_utf8 (const gchar *src,
MMModemCharset charset);
-guint8 *mm_charset_gsm_unpacked_to_utf8 (const guint8 *gsm,
- guint32 len,
- gboolean translit,
- GError **error);
-
/* Checks whether conversion to the given charset may be done without errors */
gboolean mm_charset_can_convert_to (const gchar *utf8,
MMModemCharset charset);
diff --git a/src/mm-sms-part-3gpp.c b/src/mm-sms-part-3gpp.c
index f467c97b..29b49a68 100644
--- a/src/mm-sms-part-3gpp.c
+++ b/src/mm-sms-part-3gpp.c
@@ -133,11 +133,13 @@ sms_decode_address (const guint8 *address,
address++;
if (addrtype == SMS_NUMBER_TYPE_ALPHA) {
- g_autofree guint8 *unpacked = NULL;
- guint32 unpacked_len;
+ g_autoptr(GByteArray) unpacked_array = NULL;
+ guint8 *unpacked = NULL;
+ guint32 unpacked_len;
unpacked = mm_charset_gsm_unpack (address, (len * 4) / 7, 0, &unpacked_len);
- utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len, FALSE, error);
+ unpacked_array = g_byte_array_new_take (unpacked, unpacked_len);
+ utf8 = mm_modem_charset_bytearray_to_utf8 (unpacked_array, MM_MODEM_CHARSET_GSM, FALSE, error);
} else if (addrtype == SMS_NUMBER_TYPE_INTL &&
addrplan == SMS_NUMBER_PLAN_TELEPHONE) {
/* International telphone number, format as "+1234567890" */
@@ -249,12 +251,14 @@ sms_decode_text (const guint8 *text,
GError **error)
{
if (encoding == MM_SMS_ENCODING_GSM7) {
- g_autofree guint8 *unpacked = NULL;
- guint32 unpacked_len;
- gchar *utf8;
+ g_autoptr(GByteArray) unpacked_array = NULL;
+ guint8 *unpacked = NULL;
+ guint32 unpacked_len;
+ gchar *utf8;
unpacked = mm_charset_gsm_unpack ((const guint8 *) text, len, bit_offset, &unpacked_len);
- utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked, unpacked_len, FALSE, error);
+ unpacked_array = g_byte_array_new_take (unpacked, unpacked_len);
+ utf8 = mm_modem_charset_bytearray_to_utf8 (unpacked_array, MM_MODEM_CHARSET_GSM, FALSE, error);
if (utf8)
mm_obj_dbg (log_object, "converted SMS part text from GSM-7 to UTF-8: %s", utf8);
return utf8;
diff --git a/src/tests/test-charsets.c b/src/tests/test-charsets.c
index 4df104ed..d2c07297 100644
--- a/src/tests/test-charsets.c
+++ b/src/tests/test-charsets.c
@@ -27,7 +27,8 @@ common_test_gsm7 (const gchar *in_utf8)
guint32 unpacked_gsm_len_2 = 0;
g_autoptr(GByteArray) unpacked_gsm = NULL;
g_autofree guint8 *packed_gsm = NULL;
- g_autofree guint8 *unpacked_gsm_2 = NULL;
+ guint8 *unpacked_gsm_2 = NULL;
+ g_autoptr(GByteArray) unpacked_gsm_2_array = NULL;
g_autofree gchar *built_utf8 = NULL;
g_autoptr(GError) error = NULL;
@@ -56,9 +57,10 @@ common_test_gsm7 (const gchar *in_utf8)
/* Unpack */
unpacked_gsm_2 = mm_charset_gsm_unpack (packed_gsm, packed_gsm_len * 8 / 7, 0, &unpacked_gsm_len_2);
g_assert_nonnull (unpacked_gsm_2);
+ unpacked_gsm_2_array = g_byte_array_new_take (unpacked_gsm_2, unpacked_gsm_len_2);
/* And back to UTF-8 */
- built_utf8 = (gchar *) mm_charset_gsm_unpacked_to_utf8 (unpacked_gsm_2, unpacked_gsm_len_2, FALSE, &error);
+ built_utf8 = mm_modem_charset_bytearray_to_utf8 (unpacked_gsm_2_array, MM_MODEM_CHARSET_GSM, FALSE, &error);
g_assert_nonnull (built_utf8);
g_assert_no_error (error);
g_assert_cmpstr (built_utf8, ==, in_utf8);