BaseTools/C/Common: Avoid possible NULL pointer dereference

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
Hao Wu
2016-09-20 20:53:31 +08:00
parent e7700cedd9
commit 2ff3293d7b
6 changed files with 93 additions and 23 deletions

View File

@ -650,6 +650,10 @@ Returns:
ImageContext,
RelocDir->VirtualAddress + RelocDir->Size - 1
);
if (RelocBase == NULL || RelocBaseEnd == NULL || RelocBaseEnd < RelocBase) {
ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;
return RETURN_LOAD_ERROR;
}
} else {
//
// Set base and end to bypass processing below.
@ -674,6 +678,10 @@ Returns:
ImageContext,
RelocDir->VirtualAddress + RelocDir->Size - 1
);
if (RelocBase == NULL || RelocBaseEnd == NULL || RelocBaseEnd < RelocBase) {
ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;
return RETURN_LOAD_ERROR;
}
} else {
//
// Set base and end to bypass processing below.
@ -710,6 +718,10 @@ Returns:
RelocEnd = (UINT16 *) ((CHAR8 *) RelocBase + RelocBase->SizeOfBlock);
if (!(ImageContext->IsTeImage)) {
FixupBase = PeCoffLoaderImageAddress (ImageContext, RelocBase->VirtualAddress);
if (FixupBase == NULL) {
ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION;
return RETURN_LOAD_ERROR;
}
} else {
FixupBase = (CHAR8 *)(UINTN)(ImageContext->ImageAddress +
RelocBase->VirtualAddress +