nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0294-efi-ip4_config-Improve-check-to-detect-literal-IPv6-.patch

c4e390
From f865c027b51915e178945168b8f94c4148b43907 Mon Sep 17 00:00:00 2001
c4e390
From: Javier Martinez Canillas <javierm@redhat.com>
c4e390
Date: Mon, 9 Mar 2020 15:30:05 +0100
c4e390
Subject: [PATCH 294/335] efi/ip4_config: Improve check to detect literal IPv6
c4e390
 addresses
c4e390
c4e390
The grub_efi_string_to_ip4_address() function wrongly assumes that an IPv6
c4e390
address is an IPv4 address, because it doesn't take into account the case
c4e390
of a caller passing an IPv6 address as a string.
c4e390
c4e390
This leads to the grub_efi_net_parse_address() function to fail and print
c4e390
the following error message:
c4e390
c4e390
error: net/efi/net.c:785:unrecognised network address '2000:dead:beef:a::1'
c4e390
44b48a
Resolves: rhbz#1732765
44b48a
c4e390
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
c4e390
---
c4e390
 grub-core/net/efi/ip4_config.c | 13 ++++++++++++-
c4e390
 1 file changed, 12 insertions(+), 1 deletion(-)
c4e390
c4e390
diff --git a/grub-core/net/efi/ip4_config.c b/grub-core/net/efi/ip4_config.c
c4e390
index b711a5d9457..313c818b184 100644
c4e390
--- a/grub-core/net/efi/ip4_config.c
c4e390
+++ b/grub-core/net/efi/ip4_config.c
c4e390
@@ -56,9 +56,20 @@ int
c4e390
 grub_efi_string_to_ip4_address (const char *val, grub_efi_ipv4_address_t *address, const char **rest)
c4e390
 {
c4e390
   grub_uint32_t newip = 0;
c4e390
-  int i;
c4e390
+  int i, ncolon = 0;
c4e390
   const char *ptr = val;
c4e390
 
c4e390
+  /* Check that is not an IPv6 address */
c4e390
+  for (i = 0; i < grub_strlen(ptr); i++)
c4e390
+    {
c4e390
+      if (ptr[i] == '[' && i == 0)
c4e390
+        return 0;
c4e390
+
c4e390
+      if (ptr[i] == ':')
c4e390
+          if (i == 0 || ++ncolon == 2)
c4e390
+            return 0;
c4e390
+    }
c4e390
+
c4e390
   for (i = 0; i < 4; i++)
c4e390
     {
c4e390
       unsigned long t;
c4e390
-- 
c4e390
2.26.2
c4e390