4ff5f8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
4ff5f8
From: Javier Martinez Canillas <javierm@redhat.com>
4ff5f8
Date: Tue, 4 Dec 2018 10:53:49 +0100
4ff5f8
Subject: [PATCH] Fix get_entry_number() wrongly dereferencing the tail pointer
4ff5f8
4ff5f8
The get_entry_number_helper() function attempts to lookup a boot entry by
4ff5f8
either title or id matching the value of an environment variable. If they
4ff5f8
are a substring of the variable, the tail pointer is set to the first char
4ff5f8
of the remainder of the string.
4ff5f8
4ff5f8
When get_entry_number() calls this function, it checks if this first char
4ff5f8
is a NUL byte, to know if the variable matched correctly. But tail can be
4ff5f8
set to NULL as well to indicate that there isn't a remainder in the string.
4ff5f8
4ff5f8
Resolves: rhbz#1654936
4ff5f8
4ff5f8
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
4ff5f8
---
4ff5f8
 grub-core/normal/menu.c | 2 +-
4ff5f8
 1 file changed, 1 insertion(+), 1 deletion(-)
4ff5f8
4ff5f8
diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c
4ff5f8
index fc25c702f3c..7e32c498aa8 100644
4ff5f8
--- a/grub-core/normal/menu.c
4ff5f8
+++ b/grub-core/normal/menu.c
4ff5f8
@@ -563,7 +563,7 @@ get_entry_number (grub_menu_t menu, const char *name)
4ff5f8
 
4ff5f8
   grub_error_push ();
4ff5f8
   entry = get_entry_number_helper(menu, val, &tail);
4ff5f8
-  if (*tail != '\0')
4ff5f8
+  if (tail && *tail != '\0')
4ff5f8
     entry = -1;
4ff5f8
   grub_error_pop ();
4ff5f8