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