From abea19dbe10720a4ef4f9e688996d71a493cebe9 Mon Sep 17 00:00:00 2001 From: qhuang8 Date: Tue, 25 Apr 2006 05:51:23 +0000 Subject: =?UTF-8?q?PeiSmbusLib=20&=20DxeSmbusLib=20=09Remove=20Arp=20Relat?= =?UTF-8?q?ed=20interfaces=20=09Change=20the=20return=20type=20of=20SmbusQ?= =?UTF-8?q?uickWrite=20from=20=E2=80=9CBOOLEAN=E2=80=9D=20to=20=E2=80=9CVO?= =?UTF-8?q?ID=E2=80=9D=20=09Complete=20interface=20SmBusBlockProcessCall()?= =?UTF-8?q?=20=09Make=20the=20PEC=20bit=20=E2=80=9Cbit=2021=E2=80=9D=20of?= =?UTF-8?q?=20SMBUS=20address.=20If=20data=20show=20that=20MSB=20helps=20t?= =?UTF-8?q?o=20save=20code=20size=20in=20BaseSmbusLib,=20we=20may=20simply?= =?UTF-8?q?=20redefine=20it=20to=20be=20MAX=5FBIT.=20UefiLib=20=09Modify?= =?UTF-8?q?=20the=20interfaces=20in=20UefiNotTiano.c=20to=20sync=20with=20?= =?UTF-8?q?spec=20MemoryAllocationLib=20=09Add=20extra=20checking=20in=20?= =?UTF-8?q?=E2=80=9CAligned=E2=80=9D=20Memory=20services=20to=20prevent=20?= =?UTF-8?q?=E2=80=9CAllocationSize=20+=20OverAllocation=E2=80=9D=20overflo?= =?UTF-8?q?w=20in=20DxeMemoryAllocationLib.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@23 6f19259b-4bc3-4df7-8a09-765794883524 --- .../DxeMemoryAllocationLib/MemoryAllocationLib.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'MdePkg/Library/DxeMemoryAllocationLib') diff --git a/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c b/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c index a9bdf60aa1..ef643eed42 100644 --- a/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c +++ b/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c @@ -168,6 +168,13 @@ InternalAllocateAlignedPages ( // AlignmentMask = Alignment - 1; RealPages = Pages + EFI_SIZE_TO_PAGES (Alignment); + if (RealPages <= Pages) { + // + // This extra checking is to make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow. + // + return NULL; + } + Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory); if (EFI_ERROR (Status)) { return NULL; @@ -576,8 +583,8 @@ InternalAllocateAlignedPool ( UINTN AlignedAddress; UINTN AlignmentMask; UINTN OverAllocationSize; + UINTN RealAllocationSize; VOID **FreePointer; - EFI_STATUS Status; // // Alignment must be a power of two or zero. @@ -593,8 +600,15 @@ InternalAllocateAlignedPool ( // Calculate the extra memory size, over-allocate memory pool and get the aligned memory address. // OverAllocationSize = sizeof (RawAddress) + AlignmentMask; - Status = gBS->AllocatePool (PoolType, AllocationSize + OverAllocationSize, &RawAddress); - if (EFI_ERROR (Status)) { + RealAllocationSize = AllocationSize + OverAllocationSize; + if (RealAllocationSize <= AllocationSize ) { + // + // This extra checking is to make sure that AllocationSize plus OverAllocationSize does not overflow. + // + return NULL; + } + RawAddress = InternalAllocatePool (PoolType, RealAllocationSize); + if (RawAddress == NULL) { return NULL; } AlignedAddress = ((UINTN) RawAddress + OverAllocationSize) & ~AlignmentMask; -- cgit v1.2.3