From: Andrei Borzenkov Date: Sat, 25 Feb 2017 05:39:38 +0000 (+0300) Subject: efi: strip off final NULL from File Path in grub_efi_get_filename X-Git-Tag: 2.02-rc2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=892dfbe113d08c18e51d7c27eee5094f3da530ec;p=thirdparty%2Fgrub.git efi: strip off final NULL from File Path in grub_efi_get_filename UEFI 2.6 9.3.6.4 File Path Media Device Path says that Path Name is "A NULL-terminated Path string including directory and file names". Strip final NULL from Path Name in each File Path node when constructing full path. To be on safe side, strip all of them. Fixes failure chainloading grub from grub, when loaded grub truncates image path and does not find its grub.cfg. https://bugzilla.opensuse.org/show_bug.cgi?id=1026344 This was triggered by commit ce95549cc54b5d6f494608a7c390dba3aab4fba7; before it we built Path Name without trailing NULL, and apparently all other bootloaders use single File Path node, thus not exposing this bug. --- diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c index caf9bcc41..d467785fc 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c @@ -366,6 +366,9 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) len = ((GRUB_EFI_DEVICE_PATH_LENGTH (dp) - 4) / sizeof (grub_efi_char16_t)); fp = (grub_efi_file_path_device_path_t *) dp; + /* According to EFI spec Path Name is NULL terminated */ + while (len > 0 && fp->path_name[len - 1] == 0) + len--; p = (char *) grub_utf16_to_utf8 ((unsigned char *) p, fp->path_name, len); }