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

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