Skip to contentSkip to conversation

loader/linux: Only emit newc directory once

PATCH In review Glenn Washburn 2 participants 2 messages Jun 28, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 loader/linux: Only emit newc directory once

When creating at runtime a newc initrd via arguments to initrd with "newc:" prefixes, only emit a directory path record once. The original code intended to do that by bailing out of emiting the record when the record to be created matches an existing record. However, this does not happen because grub_memcmp() is improperly checked.

Generating duplicate newc directory records does not cause any problems because the linux unpacker will skip it once it sees the directory already exists. This fix saves a little processing and makes the generated newc cpio archive a little smaller.

Fixes 92750e4c60 (Add ability to generate newc additions on runtime.)
---
 grub-core/loader/linux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/loader/linux.c +1 -1
index 3948302d2c43..cb2c3f6e4f06 100644
@@ -114,7 +114,7 @@ insert_dir (const char *name, struct dir **root,
 	break;
 
       for (cur = *root; cur; cur = cur->next)
-	if (grub_memcmp (cur->name, cb, ce - cb)
+	if (grub_memcmp (cur->name, cb, ce - cb) == 0
 	    && cur->name[ce - cb] == 0)
 	  break;
       if (!cur)
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Glenn Washburn

When creating at runtime a newc initrd via arguments to initrd with "newc:" prefixes, only emit a directory path record once. The original code intended to do that by bailing out of emiting the record when the record to be created matches an existing record. However, this does not happen because grub_memcmp() is improperly checked.

Quoted 7 lines

Generating duplicate newc directory records does not cause any problems because the linux unpacker will skip it once it sees the directory already exists. This fix saves a little processing and makes the generated newc cpio archive a little smaller.

Fixes 92750e4c60 (Add ability to generate newc additions on runtime.)

Daniel