From: Glenn Washburn Date: Wed, 28 Jun 2023 07:25:16 +0000 (-0500) Subject: loader/linux: Only emit newc directory once X-Git-Tag: grub-2.12-rc1~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=16b09cd056a271e7a09a3406411561393a95761a;p=thirdparty%2Fgrub.git 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 emitting 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.) Signed-off-by: Glenn Washburn Reviewed-by: Daniel Kiper --- diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c index 3948302d2..cb2c3f6e4 100644 --- a/grub-core/loader/linux.c +++ b/grub-core/loader/linux.c @@ -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)