dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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