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

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