RelocDir->VirtualAddress + RelocDir->Size - 1,\r
TeStrippedOffset\r
);\r
- if (RelocBase == NULL || RelocBaseEnd == NULL || RelocBaseEnd < RelocBase) {\r
+ if (RelocBase == NULL || RelocBaseEnd == NULL || (UINTN) RelocBaseEnd < (UINTN) RelocBase) {\r
ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;\r
return RETURN_LOAD_ERROR;\r
}\r
// Run the relocation information and apply the fixups\r
//\r
FixupData = ImageContext->FixupData;\r
- while (RelocBase < RelocBaseEnd) {\r
+ while ((UINTN) RelocBase < (UINTN) RelocBaseEnd) {\r
\r
Reloc = (UINT16 *) ((CHAR8 *) RelocBase + sizeof (EFI_IMAGE_BASE_RELOCATION));\r
//\r
//\r
// Run this relocation record\r
//\r
- while (Reloc < RelocEnd) {\r
+ while ((UINTN) Reloc < (UINTN) RelocEnd) {\r
Fixup = PeCoffLoaderImageAddress (ImageContext, RelocBase->VirtualAddress + (*Reloc & 0xFFF), TeStrippedOffset);\r
if (Fixup == NULL) {\r
ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;\r
// is present in the image. You have to check the NumberOfRvaAndSizes in\r
// the optional header to verify a desired directory entry is there.\r
//\r
+ RelocBase = NULL;\r
+ RelocBaseEnd = NULL;\r
if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) {\r
RelocDir = DataDirectory + EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC;\r
- RelocBase = (EFI_IMAGE_BASE_RELOCATION *) PeCoffLoaderImageAddress (&ImageContext, RelocDir->VirtualAddress, 0);\r
- RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *) PeCoffLoaderImageAddress (&ImageContext,\r
- RelocDir->VirtualAddress + RelocDir->Size - 1,\r
- 0\r
- );\r
+ if ((RelocDir != NULL) && (RelocDir->Size > 0)) {\r
+ RelocBase = (EFI_IMAGE_BASE_RELOCATION *) PeCoffLoaderImageAddress (&ImageContext, RelocDir->VirtualAddress, 0);\r
+ RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *) PeCoffLoaderImageAddress (&ImageContext,\r
+ RelocDir->VirtualAddress + RelocDir->Size - 1,\r
+ 0\r
+ );\r
+ }\r
+ if (RelocBase == NULL || RelocBaseEnd == NULL || (UINTN) RelocBaseEnd < (UINTN) RelocBase) {\r
+ //\r
+ // relocation block is not valid, just return\r
+ //\r
+ return;\r
+ }\r
} else {\r
//\r
// Cannot find relocations, cannot continue to relocate the image, ASSERT for this invalid image.\r
//\r
FixupData = RelocationData;\r
RelocBaseOrig = RelocBase;\r
- while (RelocBase < RelocBaseEnd) {\r
+ while ((UINTN) RelocBase < (UINTN) RelocBaseEnd) {\r
//\r
// Add check for RelocBase->SizeOfBlock field.\r
//\r
//\r
// Run this relocation record\r
//\r
- while (Reloc < RelocEnd) {\r
+ while ((UINTN) Reloc < (UINTN) RelocEnd) {\r
\r
Fixup = PeCoffLoaderImageAddress (&ImageContext, RelocBase->VirtualAddress + (*Reloc & 0xFFF), 0);\r
if (Fixup == NULL) {\r