From 5cfafa075aa238fbe6de41f06d6d2b1d2cb41678 Mon Sep 17 00:00:00 2001 From: mdkinney Date: Thu, 1 Oct 2009 23:48:00 +0000 Subject: [PATCH] Check to see if the section size of non-zero before failing a load operation due to a NULL base or end address git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9326 6f19259b-4bc3-4df7-8a09-765794883524 --- MdePkg/Library/BasePeCoffLib/BasePeCoff.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c index 5be6e90379..eeabbb24bc 100644 --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c @@ -925,6 +925,14 @@ PeCoffLoaderLoadImage ( // Section = FirstSection; for (Index = 0, MaxEnd = NULL; Index < NumberOfSections; Index++) { + // + // Read the section + // + Size = (UINTN) Section->Misc.VirtualSize; + if ((Size == 0) || (Size > Section->SizeOfRawData)) { + Size = (UINTN) Section->SizeOfRawData; + } + // // Compute sections address // @@ -935,9 +943,9 @@ PeCoffLoaderLoadImage ( ); // - // If the base start or end address resolved to 0, then fail. + // If the size of the section is non-zero and the base address or end address resolved to 0, then fail. // - if ((Base == NULL) || (End == NULL)) { + if ((Size > 0) && ((Base == NULL) || (End == NULL))) { ImageContext->ImageError = IMAGE_ERROR_SECTION_NOT_LOADED; return RETURN_LOAD_ERROR; } @@ -951,14 +959,6 @@ PeCoffLoaderLoadImage ( MaxEnd = End; } - // - // Read the section - // - Size = (UINTN) Section->Misc.VirtualSize; - if ((Size == 0) || (Size > Section->SizeOfRawData)) { - Size = (UINTN) Section->SizeOfRawData; - } - if (Section->SizeOfRawData > 0) { if (!(ImageContext->IsTeImage)) { Status = ImageContext->ImageRead (