File grub2-efi-check-path-non-null-before-grub_strrchr.patch of Package grub2.4793

From 004a2b1efdd782cf946387d2060ad9250d61c435 Mon Sep 17 00:00:00 2001
From: Leif Lindholm <leif.lindholm@linaro.org>
Date: Mon, 17 Nov 2014 14:11:01 +0000
Subject: [PATCH 02/15] efi: check *path non-null before grub_strrchr

The EFI version of grub_machine_get_bootlocation crops the boot image
name back to the last / in order to get a directory path. However, it
does not check that *name is actually set before calling grub_strrchr
to do this, and neither does grub_strrchr before dereferencing a NULL
pointer.

Parent function, grub_set_prefix_and_root, does check the pointer
before using.
---
 ChangeLog                 |  5 +++++
 grub-core/kern/efi/init.c | 11 +++++++----
 2 files changed, 12 insertions(+), 4 deletions(-)

Index: grub-2.02~beta2/grub-core/kern/efi/init.c
===================================================================
--- grub-2.02~beta2.orig/grub-core/kern/efi/init.c
+++ grub-2.02~beta2/grub-core/kern/efi/init.c
@@ -63,10 +63,13 @@ grub_machine_get_bootlocation (char **de
   if (!*device && grub_efi_net_config)
     grub_efi_net_config (image->device_handle, device, path);
 
-  /* Get the directory.  */
-  p = grub_strrchr (*path, '/');
-  if (p)
-    *p = '\0';
+  if (*path)
+    {
+      /* Get the directory.  */
+      p = grub_strrchr (*path, '/');
+      if (p)
+        *p = '\0';
+    }
 }
 
 void