aboutsummaryrefslogtreecommitdiff
path: root/libmm-glib/mm-common-helpers.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2021-02-14 10:43:35 +0100
committerAleksander Morgado <aleksander@aleksander.es>2021-02-23 11:35:11 +0000
commit8c30a6b6f813114d0cdc6b8a04ae4336c8393d48 (patch)
tree4c1aae643e6d65387144a956ce3a7dd94034486d /libmm-glib/mm-common-helpers.c
parenta211981d4a12b0ef6cab48b7a04ae9e5674cac01 (diff)
libmm-glib,common-helpers: hexstr2bin fails on empty input string
Also, remove the trailing NUL byte that was appended to the output binary stream, as it's not needed in any case.
Diffstat (limited to 'libmm-glib/mm-common-helpers.c')
-rw-r--r--libmm-glib/mm-common-helpers.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/libmm-glib/mm-common-helpers.c b/libmm-glib/mm-common-helpers.c
index 3a97e3be..30f9f94f 100644
--- a/libmm-glib/mm-common-helpers.c
+++ b/libmm-glib/mm-common-helpers.c
@@ -1701,6 +1701,12 @@ mm_utils_hexstr2bin (const gchar *hex,
if (len < 0)
len = strlen (hex);
+ if (len == 0) {
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS,
+ "Hex conversion failed: empty string");
+ return NULL;
+ }
+
/* Length must be a multiple of 2 */
if ((len % 2) != 0) {
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_INVALID_ARGS,
@@ -1708,7 +1714,7 @@ mm_utils_hexstr2bin (const gchar *hex,
return NULL;
}
- opos = buf = g_malloc0 ((len / 2) + 1);
+ opos = buf = g_malloc0 (len / 2);
for (i = 0; i < len; i += 2) {
a = mm_utils_hex2byte (ipos);
if (a < 0) {