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

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