]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Be more explicit where to look for sections
authorJan Janssen <medhefgo@web.de>
Sat, 10 Sep 2022 06:24:41 +0000 (08:24 +0200)
committerJan Janssen <medhefgo@web.de>
Sat, 10 Sep 2022 06:24:41 +0000 (08:24 +0200)
It only really makes sense to fetch the location from either one of
these fields, depending on whether we are looking at an in-memory
(relocated) or a file PE image.

src/boot/efi/pe.c

index 8d7061d55b21e92b1860a8e1a2794658f7430411..2b260d42122d18c9f0009731615ee6035d9b371b 100644 (file)
@@ -142,12 +142,13 @@ static void locate_sections(
                 const PeSectionHeader section_table[],
                 UINTN n_table,
                 const char * const sections[],
-                UINTN *addrs,
                 UINTN *offsets,
-                UINTN *sizes) {
+                UINTN *sizes,
+                bool in_memory) {
 
         assert(section_table);
         assert(sections);
+        assert(offsets);
         assert(sizes);
 
         for (UINTN i = 0; i < n_table; i++) {
@@ -157,10 +158,7 @@ static void locate_sections(
                         if (memcmp(sect->Name, sections[j], strlen8(sections[j])) != 0)
                                 continue;
 
-                        if (addrs)
-                                addrs[j] = sect->VirtualAddress;
-                        if (offsets)
-                                offsets[j] = sect->PointerToRawData;
+                        offsets[j] = in_memory ? sect->VirtualAddress : sect->PointerToRawData;
                         sizes[j] = sect->VirtualSize;
                 }
         }
@@ -178,8 +176,8 @@ static uint32_t get_compatibility_entry_address(const DosFileHeader *dos, const
                         pe->FileHeader.NumberOfSections,
                         sections,
                         &addr,
-                        NULL,
-                        &size);
+                        &size,
+                        /*in_memory=*/true);
 
         if (size == 0)
                 return 0;
@@ -270,8 +268,8 @@ EFI_STATUS pe_memory_locate_sections(const void *base, const char * const sectio
                         pe->FileHeader.NumberOfSections,
                         sections,
                         addrs,
-                        NULL,
-                        sizes);
+                        sizes,
+                        /*in_memory=*/true);
 
         return EFI_SUCCESS;
 }
@@ -334,7 +332,7 @@ EFI_STATUS pe_file_locate_sections(
                 return EFI_LOAD_ERROR;
 
         locate_sections(section_table, pe.FileHeader.NumberOfSections,
-                        sections, NULL, offsets, sizes);
+                        sections, offsets, sizes, /*in_memory=*/false);
 
         return EFI_SUCCESS;
 }