Blame SOURCES/0013-shim-Properly-generate-absolute-paths-from-relative-.patch

d1e1c8
From 79be2af5260b1f2e2a4680e74e14da0fdb42b570 Mon Sep 17 00:00:00 2001
d1e1c8
From: Javier Martinez Canillas <javierm@redhat.com>
d1e1c8
Date: Fri, 7 Sep 2018 14:11:02 +0200
d1e1c8
Subject: [PATCH 13/62] shim: Properly generate absolute paths from relative
d1e1c8
 image paths
d1e1c8
d1e1c8
The generate_path_from_image_path() doesn't properly handle the case when
d1e1c8
shim is invoked using a relative path (e.g: from the EFI shell). In that
d1e1c8
function, always the last component is stripped from absolute file path
d1e1c8
to calculate the dirname, and this is concatenated with the image path.
d1e1c8
d1e1c8
But if the path is a relative one, the function will wrongly concatenate
d1e1c8
the dirname with the relative image path, i.e:
d1e1c8
d1e1c8
 Shell> FS0:
d1e1c8
 FS0:\> cd EFI
d1e1c8
 FS0:\EFI\> BOOT\BOOTX64.EFI
d1e1c8
 Failed to open \EFI\BOOT\BOOT\BOOTX64.EFI - Not found
d1e1c8
 Failed to load image \EFI\BOOT\BOOT\BOOTX64.EFI: Not found
d1e1c8
 start_image() returned Not found
d1e1c8
d1e1c8
Calculate the image path basename and concatenate that with the dirname.
d1e1c8
d1e1c8
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
d1e1c8
Reviewed-by: Maran Wilson maran.wilson@oracle.com
d1e1c8
Tested-by: Maran Wilson maran.wilson@oracle.com
d1e1c8
Upstream-commit-id: a625fa5096c
d1e1c8
---
d1e1c8
 shim.c | 6 ++++--
d1e1c8
 1 file changed, 4 insertions(+), 2 deletions(-)
d1e1c8
d1e1c8
diff --git a/shim.c b/shim.c
d1e1c8
index 05fc65005d1..5ab23d03db4 100644
d1e1c8
--- a/shim.c
d1e1c8
+++ b/shim.c
d1e1c8
@@ -1610,9 +1610,11 @@ static EFI_STATUS generate_path_from_image_path(EFI_LOADED_IMAGE *li,
d1e1c8
 		bootpath[j] = '\0';
d1e1c8
 	}
d1e1c8
 
d1e1c8
-	while (*ImagePath == '\\')
d1e1c8
-		ImagePath++;
d1e1c8
+	for (i = 0, last = 0; i < StrLen(ImagePath); i++)
d1e1c8
+		if (ImagePath[i] == '\\')
d1e1c8
+			last = i + 1;
d1e1c8
 
d1e1c8
+	ImagePath = ImagePath + last;
d1e1c8
 	*PathName = AllocatePool(StrSize(bootpath) + StrSize(ImagePath));
d1e1c8
 
d1e1c8
 	if (!*PathName) {
d1e1c8
-- 
d1e1c8
2.26.2
d1e1c8