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:
Beniamino Galvani 2016-06-14 22:55:17 +02:00 committed by Stephen Hemminger
parent 24604eb287
commit 9ba4126dc4

View File

@ -924,6 +924,7 @@ __u8 *hexstring_a2n(const char *str, __u8 *buf, int blen, unsigned int *len)
strncpy(tmpstr, str, 2);
tmpstr[2] = '\0';
errno = 0;
tmp = strtoul(tmpstr, &endptr, 16);
if (errno != 0 || tmp > 0xFF || *endptr != '\0')
return NULL;