From 9dc735426a9d378a61b92c5d3795d2a3b1d7b3b3 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 19 Mar 2025 10:23:26 +0900 Subject: [PATCH] boot: always pass an array of PeSectionVector to pe_locate_sections() Hopefully silences false-positive warnings by Coverity. Fixes CID#1549198, CID#1549199, CID#1564903. --- src/boot/boot.c | 12 ++++++------ src/boot/pe.c | 21 +++++++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/boot/boot.c b/src/boot/boot.c index e7ae98021f1..818614a69e6 100644 --- a/src/boot/boot.c +++ b/src/boot/boot.c @@ -1814,19 +1814,19 @@ static bool is_sd_boot(EFI_FILE *root_dir, const char16_t *loader_path) { if (err != EFI_SUCCESS) return false; - PeSectionVector vector = {}; + PeSectionVector vector[1] = {}; pe_locate_profile_sections( section_table, n_section_table, section_names, /* profile= */ UINT_MAX, /* validate_base= */ 0, - &vector); - if (vector.memory_size != STRLEN(SD_MAGIC)) + vector); + if (vector[0].memory_size != STRLEN(SD_MAGIC)) return false; - err = file_handle_read(handle, vector.file_offset, vector.file_size, &content, &read); - if (err != EFI_SUCCESS || vector.file_size != read) + err = file_handle_read(handle, vector[0].file_offset, vector[0].file_size, &content, &read); + if (err != EFI_SUCCESS || vector[0].file_size != read) return false; return memcmp(content, SD_MAGIC, STRLEN(SD_MAGIC)) == 0; @@ -2093,7 +2093,7 @@ static void boot_entry_add_type2( /* and now iterate through possible profiles, and create a menu item for each profile we find */ for (unsigned profile = 0; profile < UNIFIED_PROFILES_MAX; profile ++) { - PeSectionVector sections[_SECTION_MAX]; + PeSectionVector sections[_SECTION_MAX] = {}; /* Start out with the base sections */ memcpy(sections, base_sections, sizeof(sections)); diff --git a/src/boot/pe.c b/src/boot/pe.c index 04139c7ff68..1a0feb633e3 100644 --- a/src/boot/pe.c +++ b/src/boot/pe.c @@ -349,21 +349,22 @@ static void pe_locate_sections( if (!firmware_devicetree_exists()) { /* Find HWIDs table and search for the current device */ - PeSectionVector hwids_section = {}; + static const char *const hwid_section_names[] = { ".hwids", NULL }; + PeSectionVector hwids_section[1] = {}; pe_locate_sections_internal( section_table, n_section_table, - (const char *const[]) { ".hwids", NULL }, + hwid_section_names, validate_base, /* device_table */ NULL, /* device */ NULL, - &hwids_section); + hwids_section); - if (PE_SECTION_VECTOR_IS_SET(&hwids_section)) { - hwids = (const uint8_t *) SIZE_TO_PTR(validate_base) + hwids_section.memory_offset; + if (PE_SECTION_VECTOR_IS_SET(hwids_section)) { + hwids = (const uint8_t *) SIZE_TO_PTR(validate_base) + hwids_section[0].memory_offset; - EFI_STATUS err = chid_match(hwids, hwids_section.memory_size, DEVICE_TYPE_DEVICETREE, &device); + EFI_STATUS err = chid_match(hwids, hwids_section[0].memory_size, DEVICE_TYPE_DEVICETREE, &device); if (err != EFI_SUCCESS) { log_error_status(err, "HWID matching failed, no DT blob will be selected: %m"); hwids = NULL; @@ -390,15 +391,15 @@ static uint32_t get_compatibility_entry_address(const DosFileHeader *dos, const assert(pe); static const char *const section_names[] = { ".compat", NULL }; - PeSectionVector vector = {}; + PeSectionVector vector[1] = {}; pe_locate_sections( (const PeSectionHeader *) ((const uint8_t *) dos + section_table_offset(dos, pe)), pe->FileHeader.NumberOfSections, section_names, PTR_TO_SIZE(dos), - &vector); + vector); - if (!PE_SECTION_VECTOR_IS_SET(&vector)) /* not found */ + if (!PE_SECTION_VECTOR_IS_SET(vector)) /* not found */ return 0; typedef struct { @@ -408,7 +409,7 @@ static uint32_t get_compatibility_entry_address(const DosFileHeader *dos, const uint32_t entry_point; } _packed_ LinuxPeCompat1; - size_t addr = vector.memory_offset, size = vector.memory_size; + size_t addr = vector[0].memory_offset, size = vector[0].memory_size; while (size >= sizeof(LinuxPeCompat1) && addr % alignof(LinuxPeCompat1) == 0) { const LinuxPeCompat1 *compat = (const LinuxPeCompat1 *) ((const uint8_t *) dos + addr); -- 2.47.3