OcMachoLib: Verify FileSize can handle at least the header and the minimal LC size.

This commit is contained in:
Download-Fritz 2018-10-19 14:10:46 +02:00
parent c6bf9d0590
commit 1ce48bf040

View File

@ -37,6 +37,7 @@ MachoInitializeContext (
OUT OC_MACHO_CONTEXT *Context
)
{
UINTN MinCommandsSize;
UINTN TopOfCommands;
UINTN Index;
CONST MACH_LOAD_COMMAND *Command;
@ -44,8 +45,11 @@ MachoInitializeContext (
//
// Verify MACH-O Header sanity.
//
TopOfCommands = ((UINTN)MachHeader->Commands + MachHeader->CommandsSize);
if ((MachHeader->Signature != MACH_HEADER_64_SIGNATURE)
TopOfCommands = ((UINTN)MachHeader->Commands + MachHeader->CommandsSize);
MinCommandsSize = (MachHeader->NumberOfCommands * sizeof (*MachHeader->Commands));
if ((FileSize < sizeof (*MachHeader))
|| (MachHeader->Signature != MACH_HEADER_64_SIGNATURE)
|| (MachHeader->CommandsSize < MinCommandsSize)
|| (TopOfCommands > ((UINTN)MachHeader + FileSize))) {
return FALSE;
}