]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: ensure profile IDs do not get leaked and overwritten when there are tries suffixes
authorLuca Boccassi <luca.boccassi@gmail.com>
Sat, 22 Nov 2025 00:25:21 +0000 (00:25 +0000)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 23 Nov 2025 02:04:51 +0000 (11:04 +0900)
boot_entry_parse_tries() replaces the id, which means the id
with the profile appended is lost (leaked) and replaced by a plain filename
in case there are tries suffixes. This means the wrong order is used in
displaying the entries in the menu, as the main profile is always last
given id_without_profile has the tries suffixes and sorts higher,
while the main profile has no id_without_profile and the id sorts lower
since it does not have the tries suffix.

Follow-up for 4301ad00ef715885be5c3bdf84c152030b7d36ff

src/boot/boot.c

index 3632f005c16794c7ac35981cab5cd3aff2550950..0ff98709d5594fb7637afe2e3edd348f61c8617b 100644 (file)
@@ -2288,15 +2288,6 @@ static void boot_entry_add_type2(
                                 }
                 }
 
-                _cleanup_free_ char16_t *id = NULL;
-                if (profile > 0) {
-                        if (profile_id)
-                                id = xasprintf("%ls@%ls", filename, profile_id);
-                        else
-                                id = xasprintf("%ls@%u", filename, profile);
-                } else
-                        id = xstrdup16(filename);
-
                 _cleanup_free_ char16_t *title = NULL;
                 if (profile_title)
                         title = xasprintf("%ls (%ls)", good_name, profile_title);
@@ -2310,8 +2301,6 @@ static void boot_entry_add_type2(
 
                 BootEntry *entry = xnew(BootEntry, 1);
                 *entry = (BootEntry) {
-                        .id = strtolower16(TAKE_PTR(id)),
-                        .id_without_profile = profile > 0 ? strtolower16(xstrdup16(filename)) : NULL,
                         .type = LOADER_TYPE2_UKI,
                         .title = TAKE_PTR(title),
                         .version = xstrdup16(good_version),
@@ -2325,9 +2314,25 @@ static void boot_entry_add_type2(
                         .call = call_image_start,
                 };
 
-                config_add_entry(config, entry);
                 boot_entry_parse_tries(entry, path, filename, u".efi");
 
+                /* If the filename had no tries suffixes then the id won't be set by the above call, do it now */
+                if (!entry->id)
+                        entry->id = strtolower16(xstrdup16(filename));
+
+                /* Ensure the secondary profiles IDs also have the tries suffix stripped, to match the primary */
+                if (profile > 0) {
+                        entry->id_without_profile = TAKE_PTR(entry->id);
+
+                        if (profile_id)
+                                entry->id = xasprintf("%ls@%ls", entry->id_without_profile, profile_id);
+                        else
+                                entry->id = xasprintf("%ls@%u", entry->id_without_profile, profile);
+
+                }
+
+                config_add_entry(config, entry);
+
                 if (!PE_SECTION_VECTOR_IS_SET(sections + SECTION_CMDLINE))
                         continue;