X Tutup
Skip to content

Commit ff9d65f

Browse files
committed
sd-boot: Move optional header verification into verify_pe
1 parent 785b5fc commit ff9d65f

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/boot/efi/pe.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ static inline BOOLEAN verify_pe(const struct PeFileHeader *pe) {
122122
return CompareMem(pe->Magic, PE_FILE_MAGIC, STRLEN(PE_FILE_MAGIC)) == 0 &&
123123
pe->FileHeader.Machine == TARGET_MACHINE_TYPE &&
124124
pe->FileHeader.NumberOfSections > 0 &&
125-
pe->FileHeader.NumberOfSections <= MAX_SECTIONS;
125+
pe->FileHeader.NumberOfSections <= MAX_SECTIONS &&
126+
IN_SET(pe->OptionalHeader.Magic, OPTHDR32_MAGIC, OPTHDR64_MAGIC);
126127
}
127128

128129
static inline UINTN section_table_offset(const struct DosFileHeader *dos, const struct PeFileHeader *pe) {
@@ -182,15 +183,8 @@ EFI_STATUS pe_alignment_info(
182183
return EFI_LOAD_ERROR;
183184

184185
*ret_entry_point_address = pe->OptionalHeader.AddressOfEntryPoint;
185-
186-
if (pe->OptionalHeader.Magic == OPTHDR32_MAGIC) {
187-
*ret_size_of_image = pe->OptionalHeader.SizeOfImage;
188-
*ret_section_alignment = pe->OptionalHeader.SectionAlignment;
189-
} else if (pe->OptionalHeader.Magic == OPTHDR64_MAGIC) {
190-
*ret_size_of_image = pe->OptionalHeader.SizeOfImage;
191-
*ret_section_alignment = pe->OptionalHeader.SectionAlignment;
192-
} else
193-
return EFI_UNSUPPORTED;
186+
*ret_size_of_image = pe->OptionalHeader.SizeOfImage;
187+
*ret_section_alignment = pe->OptionalHeader.SectionAlignment;
194188
return EFI_SUCCESS;
195189
}
196190

0 commit comments

Comments
 (0)
X Tutup