naccyde / rpms / iproute

Forked from rpms/iproute 8 months ago
Clone

Blame SOURCES/0170-iproute2-utils-change-hexstring_n2a-and-hexstring_a2.patch

049c96
From 60969cb2bd1782f232d1c74871642c03b429d676 Mon Sep 17 00:00:00 2001
049c96
From: Davide Caratti <dcaratti@redhat.com>
049c96
Date: Wed, 6 Jul 2016 18:41:30 +0200
049c96
Subject: [PATCH] iproute2: utils: change hexstring_n2a and hexstring_a2n to do
049c96
 not work with ":"
049c96
049c96
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1300765
049c96
Upstream Status: iproute2.git commit 316c2346f7f3
049c96
049c96
commit 316c2346f7f3e337be9a56e7ad5fc8e04cd26d63
049c96
Author: Jiri Pirko <jiri@resnulli.us>
049c96
Date:   Thu May 15 15:10:21 2014 +0200
049c96
049c96
    iproute2: utils: change hexstring_n2a and hexstring_a2n to do not work with ":"
049c96
049c96
    Signed-off-by: Jiri Pirko <jiri@resnulli.us>
049c96
049c96
Signed-off-by: Davide Caratti <dcaratti@redhat.com>
049c96
---
049c96
 lib/utils.c | 46 +++++++++++++---------------------------------
049c96
 1 file changed, 13 insertions(+), 33 deletions(-)
049c96
049c96
diff --git a/lib/utils.c b/lib/utils.c
049c96
index 1cd4fdd..7f842ae 100644
049c96
--- a/lib/utils.c
049c96
+++ b/lib/utils.c
049c96
@@ -783,10 +783,6 @@ char *hexstring_n2a(const __u8 *str, int len, char *buf, int blen)
049c96
 		sprintf(ptr, "%02x", str[i]);
049c96
 		ptr += 2;
049c96
 		blen -= 2;
049c96
-		if (i != len-1 && blen > 1) {
049c96
-			*ptr++ = ':';
049c96
-			blen--;
049c96
-		}
049c96
 	}
049c96
 	return buf;
049c96
 }
049c96
@@ -794,38 +790,22 @@ char *hexstring_n2a(const __u8 *str, int len, char *buf, int blen)
049c96
 __u8* hexstring_a2n(const char *str, __u8 *buf, int blen)
049c96
 {
049c96
 	int cnt = 0;
049c96
+	char *endptr;
049c96
 
049c96
-	for (;;) {
049c96
-		unsigned acc;
049c96
-		char ch;
049c96
-
049c96
-		acc = 0;
049c96
-
049c96
-		while ((ch = *str) != ':' && ch != 0) {
049c96
-			if (ch >= '0' && ch <= '9')
049c96
-				ch -= '0';
049c96
-			else if (ch >= 'a' && ch <= 'f')
049c96
-				ch -= 'a'-10;
049c96
-			else if (ch >= 'A' && ch <= 'F')
049c96
-				ch -= 'A'-10;
049c96
-			else
049c96
-				return NULL;
049c96
-			acc = (acc<<4) + ch;
049c96
-			str++;
049c96
-		}
049c96
-
049c96
-		if (acc > 255)
049c96
+	if (strlen(str) % 2)
049c96
+		return NULL;
049c96
+	while (cnt < blen && strlen(str) > 1) {
049c96
+		unsigned int tmp;
049c96
+		char tmpstr[3];
049c96
+
049c96
+		strncpy(tmpstr, str, 2);
049c96
+		tmpstr[2] = '\0';
049c96
+		tmp = strtoul(tmpstr, &endptr, 16);
049c96
+		if (errno != 0 || tmp > 0xFF || *endptr != '\0')
049c96
 			return NULL;
049c96
-		if (cnt < blen) {
049c96
-			buf[cnt] = acc;
049c96
-			cnt++;
049c96
-		}
049c96
-		if (ch == 0)
049c96
-			break;
049c96
-		++str;
049c96
+		buf[cnt++] = tmp;
049c96
+		str += 2;
049c96
 	}
049c96
-	if (cnt < blen)
049c96
-		memset(buf+cnt, 0, blen-cnt);
049c96
 	return buf;
049c96
 }
049c96
 
049c96
-- 
049c96
1.8.3.1
049c96