libmm-glib,common-helpers: make hexstr2bin() accept input string length

Optionally given explicitly, and -1 can be used to assume it's
NUL-terminated.
This commit is contained in:
Aleksander Morgado
2021-02-23 11:35:11 +00:00
parent 657cabcfce
commit a211981d4a
11 changed files with 16 additions and 15 deletions
+5 -4
View File
@@ -1688,6 +1688,7 @@ mm_utils_hex2byte (const gchar *hex)
gchar *
mm_utils_hexstr2bin (const gchar *hex,
gssize len,
gsize *out_len,
GError **error)
{
@@ -1695,10 +1696,10 @@ mm_utils_hexstr2bin (const gchar *hex,
g_autofree gchar *buf = NULL;
gsize i;
gint a;
gchar *opos;
gsize len;
len = strlen (hex);
gchar *opos
;
if (len < 0)
len = strlen (hex);
/* Length must be a multiple of 2 */
if ((len % 2) != 0) {
+1 -1
View File
@@ -181,7 +181,7 @@ gchar *mm_get_string_unquoted_from_match_info (GMatchInfo *match_info,
const gchar *mm_sms_delivery_state_get_string_extended (guint delivery_state);
gint mm_utils_hex2byte (const gchar *hex);
gchar *mm_utils_hexstr2bin (const gchar *hex, gsize *out_len, GError **error);
gchar *mm_utils_hexstr2bin (const gchar *hex, gssize len, gsize *out_len, GError **error);
gchar *mm_utils_bin2hexstr (const guint8 *bin, gsize len);
gboolean mm_utils_ishexstr (const gchar *hex);
+1 -1
View File
@@ -210,7 +210,7 @@ mm_altair_parse_vendor_pco_info (const gchar *pco_info, GError **error)
break;
}
pco_payload_bytes = mm_utils_hexstr2bin (pco_payload, &pco_payload_bytes_len, error);
pco_payload_bytes = mm_utils_hexstr2bin (pco_payload, -1, &pco_payload_bytes_len, error);
if (!pco_payload_bytes) {
g_prefix_error (error, "Invalid PCO payload from PCO info '%s': ", pco_info);
break;
+1 -1
View File
@@ -2335,7 +2335,7 @@ decode (MMIfaceModem3gppUssd *self,
gsize bin_len = 0;
guint32 unpacked_len;
bin = mm_utils_hexstr2bin (reply, &bin_len, error);
bin = mm_utils_hexstr2bin (reply, -1, &bin_len, error);
if (!bin)
return NULL;
+1 -1
View File
@@ -188,7 +188,7 @@ match_info_to_ip4_addr (GMatchInfo *match_info,
else
g_assert_not_reached ();
bin = mm_utils_hexstr2bin (buf, &bin_len, NULL);
bin = mm_utils_hexstr2bin (buf, -1, &bin_len, NULL);
if (!bin || bin_len != 4)
goto done;
+2 -2
View File
@@ -1311,7 +1311,7 @@ parse_mnc_length (const gchar *response,
g_autofree gchar *bin = NULL;
/* Convert hex string to binary */
bin = mm_utils_hexstr2bin (hex, &buflen, error);
bin = mm_utils_hexstr2bin (hex, -1, &buflen, error);
if (!bin) {
g_prefix_error (error, "SIM returned malformed response '%s': ", hex);
return 0;
@@ -1416,7 +1416,7 @@ parse_spn (const gchar *response,
g_autofree gchar *bin = NULL;
/* Convert hex string to binary */
bin = mm_utils_hexstr2bin (hex, &buflen, error);
bin = mm_utils_hexstr2bin (hex, -1, &buflen, error);
if (!bin) {
g_prefix_error (error, "SIM returned malformed response '%s': ", hex);
return NULL;
+1 -1
View File
@@ -169,7 +169,7 @@ mm_modem_charset_hex_to_utf8 (const gchar *src,
iconv_from = charset_iconv_from (charset);
g_return_val_if_fail (iconv_from != NULL, FALSE);
unconverted = mm_utils_hexstr2bin (src, &unconverted_len, NULL);
unconverted = mm_utils_hexstr2bin (src, -1, &unconverted_len, NULL);
if (!unconverted)
return NULL;
+1 -1
View File
@@ -1815,7 +1815,7 @@ mm_firmware_unique_id_to_qmi_unique_id (const gchar *unique_id,
gsize tmp_len;
tmp_len = 0;
tmp = (guint8 *) mm_utils_hexstr2bin (unique_id, &tmp_len, error);
tmp = (guint8 *) mm_utils_hexstr2bin (unique_id, -1, &tmp_len, error);
if (!tmp) {
g_prefix_error (error, "Unexpected character found in unique id: ");
return NULL;
+1 -1
View File
@@ -4291,7 +4291,7 @@ mm_3gpp_parse_emergency_numbers (const char *raw, GError **error)
return NULL;
}
bin = (guint8 *) mm_utils_hexstr2bin (raw, &binlen, error);
bin = (guint8 *) mm_utils_hexstr2bin (raw, -1, &binlen, error);
if (!bin) {
g_prefix_error (error, "invalid raw emergency numbers list contents: ");
return NULL;
+1 -1
View File
@@ -343,7 +343,7 @@ mm_sms_part_3gpp_new_from_pdu (guint index,
gsize pdu_len;
/* Convert PDU from hex to binary */
pdu = (guint8 *) mm_utils_hexstr2bin (hexpdu, &pdu_len, error);
pdu = (guint8 *) mm_utils_hexstr2bin (hexpdu, -1, &pdu_len, error);
if (!pdu) {
g_prefix_error (error, "Couldn't convert 3GPP PDU from hex to binary: ");
return NULL;
+1 -1
View File
@@ -321,7 +321,7 @@ mm_sms_part_cdma_new_from_pdu (guint index,
gsize pdu_len;
/* Convert PDU from hex to binary */
pdu = (guint8 *) mm_utils_hexstr2bin (hexpdu, &pdu_len, error);
pdu = (guint8 *) mm_utils_hexstr2bin (hexpdu, -1, &pdu_len, error);
if (!pdu) {
g_prefix_error (error, "Couldn't convert CDMA PDU from hex to binary: ");
return NULL;