MdePkg/BasePeCoffLib2: Only validate ExeHdrOffset when non-zero

This commit is contained in:
Marvin Häuser 2023-04-02 15:26:55 +02:00
parent 42ef8c795c
commit 7b022c46d0

View File

@ -840,6 +840,13 @@ PeCoffInitializeContext (
}
Context->ExeHdrOffset = DosHdr->e_lfanew;
//
// Verify the Execution Header offset is sufficiently aligned.
//
if (!PcdGetBool (PcdImageLoaderAllowMisalignedOffset)
&& !IS_ALIGNED (Context->ExeHdrOffset, ALIGNOF (EFI_IMAGE_NT_HEADERS_COMMON_HDR))) {
return RETURN_UNSUPPORTED;
}
} else if (!PcdGetBool (PcdImageLoaderProhibitTe)) {
//
// Assume the Image starts with the Executable Header, determine whether it
@ -865,13 +872,6 @@ PeCoffInitializeContext (
if (FileSize - Context->ExeHdrOffset < sizeof (EFI_IMAGE_NT_HEADERS_COMMON_HDR) + sizeof (UINT16)) {
return RETURN_UNSUPPORTED;
}
//
// Verify the Execution Header offset is sufficiently aligned.
//
if (!PcdGetBool (PcdImageLoaderAllowMisalignedOffset)
&& !IS_ALIGNED (Context->ExeHdrOffset, ALIGNOF (EFI_IMAGE_NT_HEADERS_COMMON_HDR))) {
return RETURN_UNSUPPORTED;
}
STATIC_ASSERT (
ALIGNOF (UINT32) <= ALIGNOF (EFI_IMAGE_NT_HEADERS_COMMON_HDR),