nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0177-Fix-grub_net_hwaddr_to_str.patch

d9d99f
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
d9d99f
From: Mark Salter <msalter@redhat.com>
d9d99f
Date: Tue, 22 Aug 2017 12:21:12 -0400
d9d99f
Subject: [PATCH] Fix grub_net_hwaddr_to_str
d9d99f
d9d99f
commit 5c3b78c92f8 introduced support for larger network hw addresses.
d9d99f
However, grub_net_hwaddr_to_str() relies on GRUB_NET_MAX_STR_ADDRESS_SIZE
d9d99f
to prevent a spurious ':' at the end of the string. So now, if actual
d9d99f
hwaddr size is less than max, an extra ':' appears at the end of the
d9d99f
string. So calculate max string size based on actual hwaddr length to
d9d99f
fix the problem.
d9d99f
d9d99f
Signed-off-by: Mark Salter <msalter@redhat.com>
d9d99f
---
d9d99f
 grub-core/net/net.c | 4 +++-
d9d99f
 1 file changed, 3 insertions(+), 1 deletion(-)
d9d99f
d9d99f
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
b71686
index a0f4d00f0..191e8e41b 100644
d9d99f
--- a/grub-core/net/net.c
d9d99f
+++ b/grub-core/net/net.c
d9d99f
@@ -770,6 +770,7 @@ grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str)
d9d99f
 {
d9d99f
   char *ptr;
d9d99f
   unsigned i;
d9d99f
+  int maxstr;
d9d99f
 
d9d99f
   if (addr->len > GRUB_NET_MAX_LINK_ADDRESS_SIZE)
d9d99f
     {
d9d99f
@@ -778,9 +779,10 @@ grub_net_hwaddr_to_str (const grub_net_link_level_address_t *addr, char *str)
d9d99f
 		    addr->type, addr->len);
d9d99f
        return;
d9d99f
     }
d9d99f
+  maxstr = addr->len * grub_strlen ("XX:");
d9d99f
   for (ptr = str, i = 0; i < addr->len; i++)
d9d99f
     {
d9d99f
-      ptr += grub_snprintf (ptr, GRUB_NET_MAX_STR_HWADDR_LEN - (ptr - str),
d9d99f
+      ptr += grub_snprintf (ptr, maxstr - (ptr - str),
d9d99f
 		     "%02x:", addr->mac[i] & 0xff);
d9d99f
     }
d9d99f
 }