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

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