mirror of
https://github.com/acidanthera/audk.git
synced 2025-04-08 17:05:09 +02:00
MdePkg: Use SafeIntLib to handle overflow
Used SafeIntLib to handle the overflow check in PeCoffLoaderRelocateImage Signed-off-by: Sachin Ganesh <sachinganesh@ami.com>
This commit is contained in:
parent
aedcaa3df8
commit
6278bbb898
@ -976,6 +976,7 @@ PeCoffLoaderRelocateImage (
|
||||
PHYSICAL_ADDRESS BaseAddress;
|
||||
UINT32 NumberOfRvaAndSizes;
|
||||
UINT32 TeStrippedOffset;
|
||||
UINT32 EndAddress;
|
||||
|
||||
ASSERT (ImageContext != NULL);
|
||||
|
||||
@ -1055,15 +1056,20 @@ PeCoffLoaderRelocateImage (
|
||||
RelocDir = &Hdr.Te->DataDirectory[0];
|
||||
}
|
||||
|
||||
if ((RelocDir != NULL) && (RelocDir->Size > 0) && ((RelocDir->Size - 1) < (MAX_UINT32 - RelocDir->VirtualAddress))) {
|
||||
RelocBase = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (ImageContext, RelocDir->VirtualAddress, TeStrippedOffset);
|
||||
RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (
|
||||
ImageContext,
|
||||
RelocDir->VirtualAddress + RelocDir->Size - 1,
|
||||
TeStrippedOffset
|
||||
);
|
||||
if ((RelocDir != NULL) && (RelocDir->Size > 0)) {
|
||||
Status = SafeUint32Add (RelocDir->VirtualAddress, (RelocDir->Size - 1), &EndAddress);
|
||||
if (!RETURN_ERROR (Status)) {
|
||||
RelocBase = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (ImageContext, RelocDir->VirtualAddress, TeStrippedOffset);
|
||||
RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *)PeCoffLoaderImageAddress (
|
||||
ImageContext,
|
||||
EndAddress,
|
||||
TeStrippedOffset
|
||||
);
|
||||
}
|
||||
|
||||
if ((RelocBase == NULL) || (RelocBaseEnd == NULL) || ((UINTN)RelocBaseEnd < (UINTN)RelocBase)) {
|
||||
ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;
|
||||
DEBUG ((DEBUG_ERROR, "Relocation block is not valid\n"));
|
||||
return RETURN_LOAD_ERROR;
|
||||
}
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user