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.
This commit is contained in:
Aleksander Morgado
2021-02-23 11:35:11 +00:00
parent a211981d4a
commit 8c30a6b6f8
+7 -1
View File
@@ -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) {