From: mdkinney Date: Tue, 19 Sep 2006 18:53:32 +0000 (+0000) Subject: Fix buffer overflow when the raw size of a section and the virtual size of a section... X-Git-Tag: edk2-stable201903~24310 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=0e84e0d7bdb833343423ac68551d019e8788325a;hp=202515b47d871f46fbd14ce1750a95e604763c5d 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 --- diff --git a/Tools/Source/TianoTools/PeiRebase/PeiRebaseExe.c b/Tools/Source/TianoTools/PeiRebase/PeiRebaseExe.c index 27c646e486..35329c74d6 100644 --- a/Tools/Source/TianoTools/PeiRebase/PeiRebaseExe.c +++ b/Tools/Source/TianoTools/PeiRebase/PeiRebaseExe.c @@ -624,12 +624,12 @@ Returns: // Allocate a buffer for the image to be loaded into. // 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) { Error (NULL, 0, 0, "memory allocation failure", NULL); return EFI_OUT_OF_RESOURCES; } - memset ((void *) MemoryImagePointer, 0, Pe32ImageSize + 0x1000); + memset ((void *) MemoryImagePointer, 0, Pe32ImageSize + 0x1000 + ImageContext.SectionAlignment); MemoryImagePointerAligned = (MemoryImagePointer + 0x0FFF) & (-1 << 12); @@ -876,13 +876,13 @@ Returns: // // 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) { Error (NULL, 0, 0, "memory allocation error on rebase of TE image", FileGuidString); free (TEBuffer); return EFI_OUT_OF_RESOURCES; } - memset ((void *) MemoryImagePointer, 0, Pe32ImageSize + 0x1000); + memset ((void *) MemoryImagePointer, 0, Pe32ImageSize + 0x1000 + ImageContext.SectionAlignment); MemoryImagePointerAligned = (MemoryImagePointer + 0x0FFF) & (-1 << 12);