dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0261-Fix-grub_net_hwaddr_to_str.patch

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