Skip to content

Commit

Permalink
shim: Properly generate absolute paths from relative image paths
Browse files Browse the repository at this point in the history
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
  • Loading branch information
martinezjavier authored and vathpela committed Sep 10, 2018
1 parent 39b8345 commit a625fa5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -1640,9 +1640,11 @@ static EFI_STATUS generate_path_from_image_path(EFI_LOADED_IMAGE *li,
bootpath[j] = '\0';
}

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

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

if (!*PathName) {
Expand Down

0 comments on commit a625fa5

Please sign in to comment.