Skip to content

Commit 6459b88

Browse files
committed
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.
1 parent df3e1af commit 6459b88

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

boot.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,19 +1814,19 @@ static bool is_sd_boot(EFI_FILE *root_dir, const char16_t *loader_path) {
18141814
if (err != EFI_SUCCESS)
18151815
return false;
18161816

1817-
PeSectionVector vector = {};
1817+
PeSectionVector vector[1] = {};
18181818
pe_locate_profile_sections(
18191819
section_table,
18201820
n_section_table,
18211821
section_names,
18221822
/* profile= */ UINT_MAX,
18231823
/* validate_base= */ 0,
1824-
&vector);
1825-
if (vector.memory_size != STRLEN(SD_MAGIC))
1824+
vector);
1825+
if (vector[0].memory_size != STRLEN(SD_MAGIC))
18261826
return false;
18271827

1828-
err = file_handle_read(handle, vector.file_offset, vector.file_size, &content, &read);
1829-
if (err != EFI_SUCCESS || vector.file_size != read)
1828+
err = file_handle_read(handle, vector[0].file_offset, vector[0].file_size, &content, &read);
1829+
if (err != EFI_SUCCESS || vector[0].file_size != read)
18301830
return false;
18311831

18321832
return memcmp(content, SD_MAGIC, STRLEN(SD_MAGIC)) == 0;
@@ -2093,7 +2093,7 @@ static void boot_entry_add_type2(
20932093

20942094
/* and now iterate through possible profiles, and create a menu item for each profile we find */
20952095
for (unsigned profile = 0; profile < UNIFIED_PROFILES_MAX; profile ++) {
2096-
PeSectionVector sections[_SECTION_MAX];
2096+
PeSectionVector sections[_SECTION_MAX] = {};
20972097

20982098
/* Start out with the base sections */
20992099
memcpy(sections, base_sections, sizeof(sections));

pe.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,21 +349,22 @@ static void pe_locate_sections(
349349

350350
if (!firmware_devicetree_exists()) {
351351
/* Find HWIDs table and search for the current device */
352-
PeSectionVector hwids_section = {};
352+
static const char *const hwid_section_names[] = { ".hwids", NULL };
353+
PeSectionVector hwids_section[1] = {};
353354

354355
pe_locate_sections_internal(
355356
section_table,
356357
n_section_table,
357-
(const char *const[]) { ".hwids", NULL },
358+
hwid_section_names,
358359
validate_base,
359360
/* device_table */ NULL,
360361
/* device */ NULL,
361-
&hwids_section);
362+
hwids_section);
362363

363-
if (PE_SECTION_VECTOR_IS_SET(&hwids_section)) {
364-
hwids = (const uint8_t *) SIZE_TO_PTR(validate_base) + hwids_section.memory_offset;
364+
if (PE_SECTION_VECTOR_IS_SET(hwids_section)) {
365+
hwids = (const uint8_t *) SIZE_TO_PTR(validate_base) + hwids_section[0].memory_offset;
365366

366-
EFI_STATUS err = chid_match(hwids, hwids_section.memory_size, DEVICE_TYPE_DEVICETREE, &device);
367+
EFI_STATUS err = chid_match(hwids, hwids_section[0].memory_size, DEVICE_TYPE_DEVICETREE, &device);
367368
if (err != EFI_SUCCESS) {
368369
log_error_status(err, "HWID matching failed, no DT blob will be selected: %m");
369370
hwids = NULL;
@@ -390,15 +391,15 @@ static uint32_t get_compatibility_entry_address(const DosFileHeader *dos, const
390391
assert(pe);
391392

392393
static const char *const section_names[] = { ".compat", NULL };
393-
PeSectionVector vector = {};
394+
PeSectionVector vector[1] = {};
394395
pe_locate_sections(
395396
(const PeSectionHeader *) ((const uint8_t *) dos + section_table_offset(dos, pe)),
396397
pe->FileHeader.NumberOfSections,
397398
section_names,
398399
PTR_TO_SIZE(dos),
399-
&vector);
400+
vector);
400401

401-
if (!PE_SECTION_VECTOR_IS_SET(&vector)) /* not found */
402+
if (!PE_SECTION_VECTOR_IS_SET(vector)) /* not found */
402403
return 0;
403404

404405
typedef struct {
@@ -408,7 +409,7 @@ static uint32_t get_compatibility_entry_address(const DosFileHeader *dos, const
408409
uint32_t entry_point;
409410
} _packed_ LinuxPeCompat1;
410411

411-
size_t addr = vector.memory_offset, size = vector.memory_size;
412+
size_t addr = vector[0].memory_offset, size = vector[0].memory_size;
412413

413414
while (size >= sizeof(LinuxPeCompat1) && addr % alignof(LinuxPeCompat1) == 0) {
414415
const LinuxPeCompat1 *compat = (const LinuxPeCompat1 *) ((const uint8_t *) dos + addr);

0 commit comments

Comments
 (0)