nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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