From d42ebb344d8692e0fd437ce38396d89d06017065 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 9 Feb 2025 09:53:39 +0100 Subject: [PATCH] bootctl: fix potential uninitialized memory access And while we are at it, let' get rid of have_xyz_partition_uuid variables, to simplify things. (cherry picked from commit df28afe9b2de9e480121c25f222fa487fed927ce) --- src/bootctl/bootctl-status.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/bootctl/bootctl-status.c b/src/bootctl/bootctl-status.c index 6bcb348935..3b46632b92 100644 --- a/src/bootctl/bootctl-status.c +++ b/src/bootctl/bootctl-status.c @@ -476,10 +476,9 @@ int verb_status(int argc, char *argv[], void *userdata) { for (size_t i = 0; i < ELEMENTSOF(loader_flags); i++) print_yes_no_line(i == 0, FLAGS_SET(loader_features, loader_flags[i].flag), loader_flags[i].name); - sd_id128_t loader_partition_uuid; - bool have_loader_partition_uuid = efi_loader_get_device_part_uuid(&loader_partition_uuid) >= 0; - - print_yes_no_line(false, have_loader_partition_uuid, "Boot loader set ESP information"); + sd_id128_t loader_partition_uuid = SD_ID128_NULL; + (void) efi_loader_get_device_part_uuid(&loader_partition_uuid); + print_yes_no_line(/* first= */ false, !sd_id128_is_null(loader_partition_uuid), "Boot loader set partition information"); if (current_entry) printf("Current Entry: %s\n", current_entry); @@ -488,14 +487,14 @@ int verb_status(int argc, char *argv[], void *userdata) { if (oneshot_entry && !streq_ptr(oneshot_entry, default_entry)) printf("OneShot Entry: %s\n", oneshot_entry); - if (have_loader_partition_uuid && !sd_id128_is_null(esp_uuid) && !sd_id128_equal(esp_uuid, loader_partition_uuid)) - printf("WARNING: The boot loader reports a different partition UUID than the detected ESP ("SD_ID128_UUID_FORMAT_STR" vs. "SD_ID128_UUID_FORMAT_STR")!\n", - SD_ID128_FORMAT_VAL(loader_partition_uuid), SD_ID128_FORMAT_VAL(esp_uuid)); + if (!sd_id128_is_null(loader_partition_uuid)) { + if (!sd_id128_is_null(esp_uuid) && !sd_id128_equal(esp_uuid, loader_partition_uuid)) + printf("WARNING: The boot loader reports a different partition UUID than the detected ESP ("SD_ID128_UUID_FORMAT_STR" vs. "SD_ID128_UUID_FORMAT_STR")!\n", + SD_ID128_FORMAT_VAL(loader_partition_uuid), SD_ID128_FORMAT_VAL(esp_uuid)); - if (!sd_id128_is_null(loader_partition_uuid)) printf(" Partition: /dev/disk/by-partuuid/" SD_ID128_UUID_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(loader_partition_uuid)); - else + } else printf(" Partition: n/a\n"); printf(" Loader: %s%s\n", special_glyph(SPECIAL_GLYPH_TREE_RIGHT), strna(loader_path)); printf("\n"); @@ -507,17 +506,18 @@ int verb_status(int argc, char *argv[], void *userdata) { for (size_t i = 0; i < ELEMENTSOF(stub_flags); i++) print_yes_no_line(i == 0, FLAGS_SET(stub_features, stub_flags[i].flag), stub_flags[i].name); - sd_id128_t stub_partition_uuid; - bool have_stub_partition_uuid = efi_stub_get_device_part_uuid(&stub_partition_uuid) >= 0; + sd_id128_t stub_partition_uuid = SD_ID128_NULL; + (void) efi_stub_get_device_part_uuid(&stub_partition_uuid); + + if (!sd_id128_is_null(stub_partition_uuid)) { + if (!(!sd_id128_is_null(esp_uuid) && sd_id128_equal(esp_uuid, stub_partition_uuid)) && + !(!sd_id128_is_null(xbootldr_uuid) && sd_id128_equal(xbootldr_uuid, stub_partition_uuid))) + printf("WARNING: The stub loader reports a different UUID than the detected ESP or XBOOTDLR partition ("SD_ID128_UUID_FORMAT_STR" vs. "SD_ID128_UUID_FORMAT_STR"/"SD_ID128_UUID_FORMAT_STR")!\n", + SD_ID128_FORMAT_VAL(stub_partition_uuid), SD_ID128_FORMAT_VAL(esp_uuid), SD_ID128_FORMAT_VAL(xbootldr_uuid)); - if (have_stub_partition_uuid && (!(!sd_id128_is_null(esp_uuid) && sd_id128_equal(esp_uuid, stub_partition_uuid)) && - !(!sd_id128_is_null(xbootldr_uuid) && sd_id128_equal(xbootldr_uuid, stub_partition_uuid)))) - printf("WARNING: The stub loader reports a different UUID than the detected ESP or XBOOTDLR partition ("SD_ID128_UUID_FORMAT_STR" vs. "SD_ID128_UUID_FORMAT_STR"/"SD_ID128_UUID_FORMAT_STR")!\n", - SD_ID128_FORMAT_VAL(stub_partition_uuid), SD_ID128_FORMAT_VAL(esp_uuid), SD_ID128_FORMAT_VAL(xbootldr_uuid)); - if (!sd_id128_is_null(stub_partition_uuid)) printf(" Partition: /dev/disk/by-partuuid/" SD_ID128_UUID_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(stub_partition_uuid)); - else + } else printf(" Partition: n/a\n"); printf(" Stub: %s%s\n", special_glyph(SPECIAL_GLYPH_TREE_RIGHT), strna(stub_path)); printf("\n");