Skip to content

Commit a625fa5

Browse files
martinezjaviervathpela
authored andcommitted
shim: Properly generate absolute paths from relative image paths
The generate_path_from_image_path() doesn't properly handle the case when shim is invoked using a relative path (e.g: from the EFI shell). In that function, always the last component is stripped from absolute file path to calculate the dirname, and this is concatenated with the image path. But if the path is a relative one, the function will wrongly concatenate the dirname with the relative image path, i.e: Shell> FS0: FS0:\> cd EFI FS0:\EFI\> BOOT\BOOTX64.EFI Failed to open \EFI\BOOT\BOOT\BOOTX64.EFI - Not found Failed to load image \EFI\BOOT\BOOT\BOOTX64.EFI: Not found start_image() returned Not found Calculate the image path basename and concatenate that with the dirname. Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Reviewed-by: Maran Wilson maran.wilson@oracle.com Tested-by: Maran Wilson maran.wilson@oracle.com
1 parent 39b8345 commit a625fa5

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

shim.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,9 +1640,11 @@ static EFI_STATUS generate_path_from_image_path(EFI_LOADED_IMAGE *li,
16401640
bootpath[j] = '\0';
16411641
}
16421642

1643-
while (*ImagePath == '\\')
1644-
ImagePath++;
1643+
for (i = 0, last = 0; i < StrLen(ImagePath); i++)
1644+
if (ImagePath[i] == '\\')
1645+
last = i + 1;
16451646

1647+
ImagePath = ImagePath + last;
16461648
*PathName = AllocatePool(StrSize(bootpath) + StrSize(ImagePath));
16471649

16481650
if (!*PathName) {

0 commit comments

Comments
 (0)