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

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