Fix buffer overflow when the raw size of a section and the virtual size of a section are not the same.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1564 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
mdkinney 2006-09-19 18:53:32 +00:00
parent 202515b47d
commit 0e84e0d7bd
1 changed files with 4 additions and 4 deletions

View File

@ -624,12 +624,12 @@ Returns:
// Allocate a buffer for the image to be loaded into. // Allocate a buffer for the image to be loaded into.
// //
Pe32ImageSize = GetLength (CurrentPe32Section.Pe32Section->CommonHeader.Size) - sizeof (EFI_PE32_SECTION); Pe32ImageSize = GetLength (CurrentPe32Section.Pe32Section->CommonHeader.Size) - sizeof (EFI_PE32_SECTION);
MemoryImagePointer = (UINTN) (malloc (Pe32ImageSize + 0x1000)); MemoryImagePointer = (UINTN) (malloc (Pe32ImageSize + 0x1000 + ImageContext.SectionAlignment));
if (MemoryImagePointer == 0) { if (MemoryImagePointer == 0) {
Error (NULL, 0, 0, "memory allocation failure", NULL); Error (NULL, 0, 0, "memory allocation failure", NULL);
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
memset ((void *) MemoryImagePointer, 0, Pe32ImageSize + 0x1000); memset ((void *) MemoryImagePointer, 0, Pe32ImageSize + 0x1000 + ImageContext.SectionAlignment);
MemoryImagePointerAligned = (MemoryImagePointer + 0x0FFF) & (-1 << 12); MemoryImagePointerAligned = (MemoryImagePointer + 0x0FFF) & (-1 << 12);
@ -876,13 +876,13 @@ Returns:
// //
// Allocate a buffer for the image to be loaded into. // Allocate a buffer for the image to be loaded into.
// //
MemoryImagePointer = (UINTN) (malloc (Pe32ImageSize + 0x1000)); MemoryImagePointer = (UINTN) (malloc (Pe32ImageSize + 0x1000 + ImageContext.SectionAlignment));
if (MemoryImagePointer == 0) { if (MemoryImagePointer == 0) {
Error (NULL, 0, 0, "memory allocation error on rebase of TE image", FileGuidString); Error (NULL, 0, 0, "memory allocation error on rebase of TE image", FileGuidString);
free (TEBuffer); free (TEBuffer);
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;
} }
memset ((void *) MemoryImagePointer, 0, Pe32ImageSize + 0x1000); memset ((void *) MemoryImagePointer, 0, Pe32ImageSize + 0x1000 + ImageContext.SectionAlignment);
MemoryImagePointerAligned = (MemoryImagePointer + 0x0FFF) & (-1 << 12); MemoryImagePointerAligned = (MemoryImagePointer + 0x0FFF) & (-1 << 12);