]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: always pass an array of PeSectionVector to pe_locate_sections()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 19 Mar 2025 01:23:26 +0000 (10:23 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 19 Mar 2025 01:40:31 +0000 (10:40 +0900)
Hopefully silences false-positive warnings by Coverity.
Fixes CID#1549198, CID#1549199, CID#1564903.

src/boot/boot.c
src/boot/pe.c

index e7ae98021f16c539617041aa9749d7e42a676086..818614a69e680ad1879308e5f6aefe270d6a5a3a 100644 (file)
@@ -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));
index 04139c7ff680007280e950ba060372022992174e..1a0feb633e3a945362dda0ff42d08994a147abd3 100644 (file)
@@ -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);