naccyde / rpms / iproute

Forked from rpms/iproute 5 months ago
Clone

Blame SOURCES/0172-lib-ll_addr-improve-ll_addr_n2a-a-bit.patch

049c96
From 6b0e32fa35dbb002e7b6d2b6529cd3543b07bdef Mon Sep 17 00:00:00 2001
049c96
From: Davide Caratti <dcaratti@redhat.com>
049c96
Date: Wed, 6 Jul 2016 18:41:32 +0200
049c96
Subject: [PATCH] lib/ll_addr: improve ll_addr_n2a() a bit
049c96
049c96
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1300765
049c96
Upstream Status: iproute2.git commit f63ed3e62989
049c96
049c96
commit f63ed3e629893046aca58a3bb409a3ff909a8fae
049c96
Author: Phil Sutter <phil@nwl.cc>
049c96
Date:   Tue Mar 22 19:35:19 2016 +0100
049c96
049c96
    lib/ll_addr: improve ll_addr_n2a() a bit
049c96
049c96
    Apart from making the code a bit more compact and efficient, this also
049c96
    prevents a potential buffer overflow if the passed buffer is really too
049c96
    small: Although correctly decrementing the size parameter passed to
049c96
    snprintf, it could become negative which would then wrap since snprintf
049c96
    uses (unsigned) size_t for the parameter.
049c96
049c96
    Signed-off-by: Phil Sutter <phil@nwl.cc>
049c96
049c96
Signed-off-by: Davide Caratti <dcaratti@redhat.com>
049c96
---
049c96
 lib/ll_addr.c | 15 +++------------
049c96
 1 file changed, 3 insertions(+), 12 deletions(-)
049c96
049c96
diff --git a/lib/ll_addr.c b/lib/ll_addr.c
049c96
index c12ab07..d38bc31 100644
049c96
--- a/lib/ll_addr.c
049c96
+++ b/lib/ll_addr.c
049c96
@@ -41,18 +41,9 @@ const char *ll_addr_n2a(unsigned char *addr, int alen, int type, char *buf, int
049c96
 	if (alen == 16 && type == ARPHRD_TUNNEL6) {
049c96
 		return inet_ntop(AF_INET6, addr, buf, blen);
049c96
 	}
049c96
-	l = 0;
049c96
-	for (i=0; i
049c96
-		if (i==0) {
049c96
-			snprintf(buf+l, blen, "%02x", addr[i]);
049c96
-			blen -= 2;
049c96
-			l += 2;
049c96
-		} else {
049c96
-			snprintf(buf+l, blen, ":%02x", addr[i]);
049c96
-			blen -= 3;
049c96
-			l += 3;
049c96
-		}
049c96
-	}
049c96
+	snprintf(buf, blen, "%02x", addr[0]);
049c96
+	for (i = 1, l = 2; i < alen && l < blen; i++, l += 3)
049c96
+		snprintf(buf + l, blen - l, ":%02x", addr[i]);
049c96
 	return buf;
049c96
 }
049c96
 
049c96
-- 
049c96
1.8.3.1
049c96