dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0263-Fix-grub_net_hwaddr_to_str.patch

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