aboutsummaryrefslogtreecommitdiff
path: root/src/util/elf2efi.c
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2023-11-23 14:54:12 +0000
committerMichael Brown <mcb30@ipxe.org>2023-11-23 15:07:46 +0000
commitb37d89db90566cc1dcab9fe5713bde142fbc8f63 (patch)
tree7a902fd7bf5e0a670caa745d9b21e6ddd66a8c76 /src/util/elf2efi.c
parentcc858acd3205b18934ffff19ac55f8987e9c6135 (diff)
downloadipxe-b37d89db90566cc1dcab9fe5713bde142fbc8f63.zip
ipxe-b37d89db90566cc1dcab9fe5713bde142fbc8f63.tar.gz
ipxe-b37d89db90566cc1dcab9fe5713bde142fbc8f63.tar.bz2
[efi] Fix recorded overall size of headers in NT optional header
Commit 1e4c378 ("[efi] Shrink size of data directory in PE header") reduced the number of entries used in the data directory and reduced the recorded size of the NT "optional" header, but did not also adjust the recorded overall size of the PE headers, resulting in unused space between the PE headers and the first section. Fix by reducing the initial recorded size of the PE headers by the size of the omitted data directory entries. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/util/elf2efi.c')
-rw-r--r--src/util/elf2efi.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/util/elf2efi.c b/src/util/elf2efi.c
index a807491..76d02f2 100644
--- a/src/util/elf2efi.c
+++ b/src/util/elf2efi.c
@@ -230,7 +230,12 @@ static struct pe_header efi_pe_header = {
.SectionAlignment = EFI_IMAGE_ALIGN,
.FileAlignment = EFI_FILE_ALIGN,
.SizeOfImage = EFI_IMAGE_ALIGN,
- .SizeOfHeaders = sizeof ( efi_pe_header ),
+ .SizeOfHeaders =
+ ( sizeof ( efi_pe_header ) -
+ ( ( EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES -
+ NUMBER_OF_DIRECTORY_ENTRIES ) *
+ sizeof ( efi_pe_header.nt.OptionalHeader.
+ DataDirectory[0] ) ) ),
.DllCharacteristics =
IMAGE_DLLCHARACTERISTICS_NX_COMPAT,
.NumberOfRvaAndSizes = NUMBER_OF_DIRECTORY_ENTRIES,