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

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