From: =?utf-8?b?0L3QsNCx?= <nabijaczleweli@nabijaczleweli.xyz>
Date: Mon, 2 Jun 2025 18:10:03 +0200
Subject: Format "File(\" instead of just "File(...shim....efi)" as string
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit

Before:

nabijaczleweli@chrust:/tmp/efibootmgr/efibootmgr$ efibootmgr
BootCurrent: 0001
Timeout: 2 seconds
BootOrder: 0001,0004,0002,0003,0007,0000
Boot0000* Enter Setup   FvVol(8063c21a-8e58-4576-95ce-089e87975d23)/FvFile(462caa21-7614-4503-836e-8ab6f4662331)
Boot0001* Debian GNU/Linux trixie/sid with Linux 6.6.9-amd64    HD(1,GPT,b56e9130-b36e-4b7b-9abf-6fe3cb9606c7,0x800,0x79800)/File(\KLAPKI\DD956699294C45E99FFE000DF2D986D6\6.6.9-AMD64\VMLINUZ-6.6.9-AMD64)69006e0069007400720064003d005c006b006c00610070006b0069005c00640064003900350036003600390039003200390034006300340035006500390039006600660065003000300030006400660032006400390038003600640036005c0036002e0036002e0039002d0061006d006400360034005c0069006e0069007400720064002e0069006d0067002d0036002e0036002e0039002d0061006d00640036003400200072006f006f0074003d007a00660073003a004100550054004f00200072006500730075006d0065003d0050004100520054004c004100420045004c003d006300680072007500730074002d007300770061007000200069006e00740065006c005f0069006f006d006d0075003d006f006e002000730079007300630061006c006c002e007800330032003d007900200071007500690065007400
Boot0002* eMMC Device   PciRoot(0x0)/Pci(0x1c,0x0)/eMMC(0)/Ctrl(0x0){auto_created_boot_option}
Boot0003* UEFI Shell    FvVol(8063c21a-8e58-4576-95ce-089e87975d23)/FvFile(7c04a583-9e3e-4f1c-ad65-e05268d0b4d1)
Boot0004* Debian GNU/Linux trixie/sid with Linux 6.6.9-amd64 (verbose debug)    HD(1,GPT,b56e9130-b36e-4b7b-9abf-6fe3cb9606c7,0x800,0x79800)/File(\CHRUST\6.6.9-AMD64\VMLINUZ-6.6.9-AMD64)69006e0069007400720064003d005c006b006c00610070006b0069005c00640064003900350036003600390039003200390034006300340035006500390039006600660065003000300030006400660032006400390038003600640036005c0036002e0036002e0039002d0061006d006400360034005c0069006e0069007400720064002e0069006d0067002d0036002e0036002e0039002d0061006d00640036003400200072006f006f0074003d007a00660073003a004100550054004f00200072006500730075006d0065003d0050004100520054004c004100420045004c003d006300680072007500730074002d007300770061007000200069006e00740065006c005f0069006f006d006d0075003d006f006e002000730079007300630061006c006c002e007800330032003d007900200076006500720062006f0073006500200064006500620075006700
Boot0007* debian        HD(2,GPT,4ad22847-4499-314f-8d8f-866509d94fa6,0x1000,0xff800)/File(\EFI\debian\shimx64.efi)
nabijaczleweli@chrust:/tmp/efibootmgr/efibootmgr$ efibootmgr  -u
BootCurrent: 0001
Timeout: 2 seconds
BootOrder: 0001,0004,0002,0003,0007,0000
Boot0000* Enter Setup   FvVol(8063c21a-8e58-4576-95ce-089e87975d23)/FvFile(462caa21-7614-4503-836e-8ab6f4662331)
Boot0001* Debian GNU/Linux trixie/sid with Linux 6.6.9-amd64    HD(1,GPT,b56e9130-b36e-4b7b-9abf-6fe3cb9606c7,0x800,0x79800)/File(\KLAPKI\DD956699294C45E99FFE000DF2D986D6\6.6.9-AMD64\VMLINUZ-6.6.9-AMD64)initrd=\klapki\dd956699294c45e99ffe000df2d986d6\6.6.9-amd64\initrd.img-6.6.9-amd64 root=zfs:AUTO resume=PARTLABEL=chrust-swap intel_iommu=on syscall.x32=y quiet
Boot0002* eMMC Device   PciRoot(0x0)/Pci(0x1c,0x0)/eMMC(0)/Ctrl(0x0)걎脈鼑䵙຅᫢ⱒ뉙
Boot0003* UEFI Shell    FvVol(8063c21a-8e58-4576-95ce-089e87975d23)/FvFile(7c04a583-9e3e-4f1c-ad65-e05268d0b4d1)
Boot0004* Debian GNU/Linux trixie/sid with Linux 6.6.9-amd64 (verbose debug)    HD(1,GPT,b56e9130-b36e-4b7b-9abf-6fe3cb9606c7,0x800,0x79800)/File(\CHRUST\6.6.9-AMD64\VMLINUZ-6.6.9-AMD64)initrd=\klapki\dd956699294c45e99ffe000df2d986d6\6.6.9-amd64\initrd.img-6.6.9-amd64 root=zfs:AUTO resume=PARTLABEL=chrust-swap intel_iommu=on syscall.x32=y verbose debug
Boot0007* debian        HD(2,GPT,4ad22847-4499-314f-8d8f-866509d94fa6,0x1000,0xff800)/File(\EFI\debian\shimx64.efi)

After:

$ ./src/efibootmgr
BootCurrent: 0001
Timeout: 2 seconds
BootOrder: 0001,0004,0002,0003,0007,0000
Boot0000* Enter Setup   FvVol(8063c21a-8e58-4576-95ce-089e87975d23)/FvFile(462caa21-7614-4503-836e-8ab6f4662331)
Boot0001* Debian GNU/Linux trixie/sid with Linux 6.6.9-amd64    HD(1,GPT,b56e9130-b36e-4b7b-9abf-6fe3cb9606c7,0x800,0x79800)/File(\KLAPKI\DD956699294C45E99FFE000DF2D986D6\6.6.9-AMD64\VMLINUZ-6.6.9-AMD64) File(.initrd=\klapki\dd956699294c45e99ffe000df2d986d6\6.6.9-amd64\initrd.img-6.6.9-amd64 root=zfs:AUTO resume=PARTLABEL=chrust-swap intel_iommu=on syscall.x32=y quiet)
Boot0002* eMMC Device   PciRoot(0x0)/Pci(0x1c,0x0)/eMMC(0)/Ctrl(0x0){auto_created_boot_option}
Boot0003* UEFI Shell    FvVol(8063c21a-8e58-4576-95ce-089e87975d23)/FvFile(7c04a583-9e3e-4f1c-ad65-e05268d0b4d1)
Boot0004* Debian GNU/Linux trixie/sid with Linux 6.6.9-amd64 (verbose debug)    HD(1,GPT,b56e9130-b36e-4b7b-9abf-6fe3cb9606c7,0x800,0x79800)/File(\CHRUST\6.6.9-AMD64\VMLINUZ-6.6.9-AMD64) File(.initrd=\klapki\dd956699294c45e99ffe000df2d986d6\6.6.9-amd64\initrd.img-6.6.9-amd64 root=zfs:AUTO resume=PARTLABEL=chrust-swap intel_iommu=on syscall.x32=y verbose debug)
Boot0007* debian        HD(2,GPT,4ad22847-4499-314f-8d8f-866509d94fa6,0x1000,0xff800)/File(\EFI\debian\shimx64.efi)

Closes: #195
Closes: https://bugs.debian.org/1055526
Fixes: e8ce9fe ("Try a little harder on formatting known
 Loader Optional Data blobs")
---
 src/efibootmgr.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/src/efibootmgr.c b/src/efibootmgr.c
index b980bcd..c0d9381 100644
--- a/src/efibootmgr.c
+++ b/src/efibootmgr.c
@@ -974,9 +974,6 @@ show_var_path(efi_load_option *load_option, size_t boot_data_size)
 	unsigned char *optional_data = NULL;
 	size_t optional_data_len=0;
 	bool is_shim = false;
-	const char * const shim_path_segments[] = {
-		"/File(\\EFI\\", "\\shim", ".efi)", NULL
-	};
 
 	pathlen = efi_loadopt_pathlen(load_option,
 				      boot_data_size);
@@ -1001,13 +998,7 @@ show_var_path(efi_load_option *load_option, size_t boot_data_size)
 	if (rc >= 0) {
 		printf("\t%s", text_path);
 
-		char *a = text_path;
-		for (int i = 0; a && shim_path_segments[i] != NULL; i++) {
-			a = strstr(a, shim_path_segments[i]);
-			if (a)
-				a += strlen(shim_path_segments[i]);
-		}
-		if (a && a[0] == '\0')
+		if (strstr(text_path, "/File(\\"))
 			is_shim = true;
 	}
 
