Skip to contentSkip to conversation

efi: check *path non-null before grub_strrchr

PATCH In review Leif Lindholm 2 participants 6 messages Nov 5, 2014 – Nov 15, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 grub-core/kern/efi/init.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
grub-core/kern/efi/init.c +0 -0
index 942ab02..e9c85de 100644
@@ -63,10 +63,13 @@ grub_machine_get_bootlocation (char **device, char

**path)
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
--
1.7.10.4

#1 lore raw
Quoted 6 lines · Leif Lindholm

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.

I wonder - do you actually have firmware that returns empty path?

Quoted 38 lines

Parent function, grub_set_prefix_and_root, does check the pointer before using.

---
 grub-core/kern/efi/init.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
grub-core/kern/efi/init.c +7 -4
index 942ab02..e9c85de 100644
@@ -63,10 +63,13 @@ grub_machine_get_bootlocation (char **device, char
 **path)
   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
--
1.7.10.4

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw
Quoted 9 lines · Andrei Borzenkov
Quoted 6 lines · Leif Lindholm

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.

I wonder - do you actually have firmware that returns empty path?

I did (internal development version), and that's being fixed that end too, but more graceful error handling in GRUB would still be nice.

/
Leif

#3 lore raw
Quoted 9 lines · Leif Lindholm
Quoted 8 lines · Andrei Borzenkov
Quoted 6 lines · Leif Lindholm

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.

Quoted 5 lines
Quoted 1 line

I wonder - do you actually have firmware that returns empty path?

I did (internal development version), and that's being fixed that end too, but more graceful error handling in GRUB would still be nice.

Sure. I wish we could display some meaningful warning here, but it is too early at this stage. If get_loaded_image fails to return proper image path, booting is probably screwed anyway.

You have commit access, right?

#4 lore raw
Quoted 12 lines · Andrei Borzenkov
Quoted 11 lines · Leif Lindholm
Quoted 9 lines · Andrei Borzenkov
Quoted 6 lines · Leif Lindholm

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.

I wonder - do you actually have firmware that returns empty path?

Quoted 7 lines
Quoted 3 lines

I did (internal development version), and that's being fixed that end too, but more graceful error handling in GRUB would still be nice.

Sure. I wish we could display some meaningful warning here, but it is too early at this stage. If get_loaded_image fails to return proper image path, booting is probably screwed anyway.

Indeed, but with this patch you would at least get a confused error message later on.

Quoted 1 line

You have commit access, right?

Yes - clear to push?

/
Leif

#5 lore raw

В Fri, 7 Nov 2014 14:19:58 +0000
Leif Lindholm <[email protected]> пишет:

Quoted 21 lines · Andrei Borzenkov
Quoted 12 lines · Leif Lindholm
Quoted 11 lines · Andrei Borzenkov
Quoted 9 lines · Leif Lindholm
Quoted 6 lines

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.

I wonder - do you actually have firmware that returns empty path?

Quoted 7 lines
Quoted 3 lines

I did (internal development version), and that's being fixed that end too, but more graceful error handling in GRUB would still be nice.

Sure. I wish we could display some meaningful warning here, but it is too early at this stage. If get_loaded_image fails to return proper image path, booting is probably screwed anyway.

Quoted 7 lines

Indeed, but with this patch you would at least get a confused error message later on.

Quoted 1 line

You have commit access, right?

Yes - clear to push?

Yes. It is clear bug fix.

Quoted 7 lines

/
Leif

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel