Thread (1 message) 1 message, 1 author, 2016-06-14

Re: [iproute2 PATCH] utils: fix hex digits parsing in hexstring_a2n()

From: Stephen Hemminger <hidden>
Date: 2016-06-14 21:25:39

On Tue, 14 Jun 2016 20:55:17 +0000
Beniamino Galvani [off-list ref] wrote:
quoted hunk
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 <redacted>
---
 lib/utils.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/lib/utils.c b/lib/utils.c
index 70e85b7..7dceeb5 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -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;
Applied.
The code here is doing things in a manner much harder than necessary...
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help