X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdePkg%2FLibrary%2FPeiMemoryAllocationLib%2FMemoryAllocationLib.c;h=274287cf035e216cc537f3c6aff59750efcac32a;hp=63641569ffe65d2450d59ee6c6e25ae8994faee9;hb=a3657e3e7aaaccb1b9ea1b41a72d4564452e272d;hpb=d05003bed6b96ad51fbf5d9b7b6c2897e6228245 diff --git a/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c b/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c index 63641569ff..274287cf03 100644 --- a/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c +++ b/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c @@ -158,6 +158,10 @@ InternalAllocateAlignedPages ( return NULL; } // + // Make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow. + // + ASSERT (Pages <= (MAX_ADDRESS - EFI_SIZE_TO_PAGES (Alignment))); + // // We would rather waste some memory to save PEI code size. // Memory = InternalAllocatePages (MemoryType, Pages + EFI_SIZE_TO_PAGES (Alignment)); @@ -569,6 +573,10 @@ InternalAllocateAlignedPool ( } else { AlignmentMask = Alignment - 1; } + // + // Make sure that AllocationSize plus AlignmentMask does not overflow. + // + ASSERT (AllocationSize <= (MAX_ADDRESS - AlignmentMask)); RawAddress = InternalAllocatePool (PoolType, AllocationSize + AlignmentMask); @@ -609,6 +617,11 @@ AllocateAlignedPool ( AlignmentMask = Alignment - 1; } + // + // Make sure that AllocationSize plus AlignmentMask does not overflow. + // + ASSERT (AllocationSize <= (MAX_ADDRESS - AlignmentMask)); + RawAddress = AllocatePool (AllocationSize + AlignmentMask); AlignedAddress = ((UINTN) RawAddress + AlignmentMask) & ~AlignmentMask;