utils: fix hex digits parsing in hexstring_a2n()
strtoul() only modifies errno on overflow, so if errno is not zero before calling the function its value is preserved and makes the function fail for valid inputs; initialize it. Signed-off-by: Beniamino Galvani <bgalvani@redhat.com>
This commit is contained in:
parent
24604eb287
commit
9ba4126dc4
|
|
@ -924,6 +924,7 @@ __u8 *hexstring_a2n(const char *str, __u8 *buf, int blen, unsigned int *len)
|
||||||
|
|
||||||
strncpy(tmpstr, str, 2);
|
strncpy(tmpstr, str, 2);
|
||||||
tmpstr[2] = '\0';
|
tmpstr[2] = '\0';
|
||||||
|
errno = 0;
|
||||||
tmp = strtoul(tmpstr, &endptr, 16);
|
tmp = strtoul(tmpstr, &endptr, 16);
|
||||||
if (errno != 0 || tmp > 0xFF || *endptr != '\0')
|
if (errno != 0 || tmp > 0xFF || *endptr != '\0')
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue