1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-12 13:18:14 +03:00

bootctl: fix case-sensitive comparisons in reporting bootloader entries

Fixes #30159
This commit is contained in:
ksaleem 2023-12-06 11:44:24 -05:00 committed by Luca Boccassi
parent 004e22412e
commit 9fb2a61830
2 changed files with 61 additions and 2 deletions

View File

@ -1205,8 +1205,8 @@ BootEntry* boot_config_find_entry(BootConfig *config, const char *id) {
assert(id);
for (size_t j = 0; j < config->n_entries; j++)
if (streq_ptr(config->entries[j].id, id) ||
streq_ptr(config->entries[j].id_old, id))
if (strcaseeq_ptr(config->entries[j].id, id) ||
strcaseeq_ptr(config->entries[j].id_old, id))
return config->entries + j;
return NULL;

View File

@ -149,4 +149,63 @@ TEST_RET(bootspec_extract_tries) {
return 0;
}
TEST_RET(bootspec_boot_config_find_entry) {
static const struct {
const char *fname;
const char *contents;
} entries[] = {
{
.fname = "a-10.conf",
.contents =
"title A\n"
"version 10\n"
"machine-id dd235d00696545768f6f693bfd23b15f\n",
},
{
.fname = "a-05.conf",
.contents =
"title A\n"
"version 10\n"
"machine-id dd235d00696545768f6f693bfd23b15f\n",
},
};
_cleanup_(rm_rf_physical_and_freep) char *d = NULL;
_cleanup_(boot_config_free) BootConfig config = BOOT_CONFIG_NULL;
assert_se(mkdtemp_malloc("/tmp/bootspec-testXXXXXX", &d) >= 0);
for (size_t i = 0; i < ELEMENTSOF(entries); i++) {
_cleanup_free_ char *j = NULL;
j = path_join(d, "/loader/entries/", entries[i].fname);
assert_se(j);
assert_se(write_string_file(j, entries[i].contents, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_MKDIR_0755) >= 0);
}
assert_se(boot_config_load(&config, d, NULL) >= 0);
assert_se(config.n_entries == 2);
// Test finding the first entry
BootEntry *entry = boot_config_find_entry(&config, "a-10.conf");
assert_se(entry && streq(entry->id, "a-10.conf"));
// Test finding the second entry
entry = boot_config_find_entry(&config, "a-05.conf");
assert_se(entry && streq(entry->id, "a-05.conf"));
// Test finding a non-existent entry
entry = boot_config_find_entry(&config, "nonexistent.conf");
assert_se(entry == NULL);
// Test case-insensitivity
entry = boot_config_find_entry(&config, "A-10.CONF");
assert_se(entry && streq(entry->id, "a-10.conf"));
return 0;
}
DEFINE_TEST_MAIN(LOG_INFO);