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