Reviewed-by: Liming Gao <[email protected]> > -----Original Message----- > From: Wu, Hao A > Sent: Wednesday, November 09, 2016 1:18 PM > To: [email protected] > Cc: Wu, Hao A <[email protected]>; Gao, Liming <[email protected]>; > Zhu, Yonghong <[email protected]> > Subject: [PATCH] BaseTools/PeCoffLib: Check 'RelocDir' before finding the > relocation block > > To match the code logics in MdePkg/Library/BasePeCoffLib, add checks for > 'RelocDir' before finding the relocation block. > > Cc: Liming Gao <[email protected]> > Cc: Yonghong Zhu <[email protected]> > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Hao Wu <[email protected]> > --- > BaseTools/Source/C/Common/BasePeCoff.c | 46 > ++++++++++++++++++++++------------ > 1 file changed, 30 insertions(+), 16 deletions(-) > > diff --git a/BaseTools/Source/C/Common/BasePeCoff.c > b/BaseTools/Source/C/Common/BasePeCoff.c > index 9adbdfa..692663d 100644 > --- a/BaseTools/Source/C/Common/BasePeCoff.c > +++ b/BaseTools/Source/C/Common/BasePeCoff.c > @@ -645,14 +645,21 @@ Returns: > // > if (OptionHeader.Optional32->NumberOfRvaAndSizes > > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) { > RelocDir = &OptionHeader.Optional32- > >DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC]; > - RelocBase = PeCoffLoaderImageAddress (ImageContext, RelocDir- > >VirtualAddress); > - RelocBaseEnd = PeCoffLoaderImageAddress ( > - ImageContext, > - RelocDir->VirtualAddress + RelocDir->Size - 1 > - ); > - if (RelocBase == NULL || RelocBaseEnd == NULL || RelocBaseEnd < > RelocBase) { > - ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION; > - return RETURN_LOAD_ERROR; > + if ((RelocDir != NULL) && (RelocDir->Size > 0)) { > + RelocBase = PeCoffLoaderImageAddress (ImageContext, RelocDir- > >VirtualAddress); > + RelocBaseEnd = PeCoffLoaderImageAddress ( > + 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. > + // > + RelocBase = RelocBaseEnd = 0; > } > } else { > // > @@ -673,14 +680,21 @@ Returns: > // > if (OptionHeader.Optional64->NumberOfRvaAndSizes > > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) { > RelocDir = &OptionHeader.Optional64- > >DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC]; > - RelocBase = PeCoffLoaderImageAddress (ImageContext, RelocDir- > >VirtualAddress); > - RelocBaseEnd = PeCoffLoaderImageAddress ( > - ImageContext, > - RelocDir->VirtualAddress + RelocDir->Size - 1 > - ); > - if (RelocBase == NULL || RelocBaseEnd == NULL || RelocBaseEnd < > RelocBase) { > - ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION; > - return RETURN_LOAD_ERROR; > + if ((RelocDir != NULL) && (RelocDir->Size > 0)) { > + RelocBase = PeCoffLoaderImageAddress (ImageContext, RelocDir- > >VirtualAddress); > + RelocBaseEnd = PeCoffLoaderImageAddress ( > + 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. > + // > + RelocBase = RelocBaseEnd = 0; > } > } else { > // > -- > 1.9.5.msysgit.0
_______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel

