efi: check *path non-null before grub_strrchr
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
@@ -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
Quoted 6 lines · Leif Lindholm
The EFI version of
grub_machine_get_bootlocationcrops 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 callinggrub_strrchrto do this, and neither doesgrub_strrchrbefore 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.Signed-off-by Leif Lindholm <[email protected]>--- grub-core/kern/efi/init.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)grub-core/kern/efi/init.c +7
-4@@ -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
Quoted 9 lines · Andrei Borzenkov
Quoted 6 lines · Leif Lindholm
The EFI version of
grub_machine_get_bootlocationcrops 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 callinggrub_strrchrto do this, and neither doesgrub_strrchrbefore 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
Quoted 9 lines · Leif Lindholm
Quoted 8 lines · Andrei Borzenkov
Quoted 6 lines · Leif Lindholm
The EFI version of
grub_machine_get_bootlocationcrops 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 callinggrub_strrchrto do this, and neither doesgrub_strrchrbefore 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?
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_bootlocationcrops 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 callinggrub_strrchrto do this, and neither doesgrub_strrchrbefore 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_imagefails 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
В 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_bootlocationcrops 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 callinggrub_strrchrto do this, and neither doesgrub_strrchrbefore 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_imagefails 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