//\r
AlignmentMask = Alignment - 1;\r
RealPages = Pages + EFI_SIZE_TO_PAGES (Alignment);\r
+ if (RealPages <= Pages) {\r
+ //\r
+ // This extra checking is to make sure that Pages plus EFI_SIZE_TO_PAGES (Alignment) does not overflow. \r
+ //\r
+ return NULL;\r
+ }\r
+\r
Status = gBS->AllocatePages (AllocateAnyPages, MemoryType, RealPages, &Memory);\r
if (EFI_ERROR (Status)) {\r
return NULL;\r
UINTN AlignedAddress;\r
UINTN AlignmentMask;\r
UINTN OverAllocationSize;\r
+ UINTN RealAllocationSize;\r
VOID **FreePointer;\r
- EFI_STATUS Status;\r
\r
//\r
// Alignment must be a power of two or zero.\r
// Calculate the extra memory size, over-allocate memory pool and get the aligned memory address. \r
//\r
OverAllocationSize = sizeof (RawAddress) + AlignmentMask;\r
- Status = gBS->AllocatePool (PoolType, AllocationSize + OverAllocationSize, &RawAddress);\r
- if (EFI_ERROR (Status)) {\r
+ RealAllocationSize = AllocationSize + OverAllocationSize;\r
+ if (RealAllocationSize <= AllocationSize ) {\r
+ //\r
+ // This extra checking is to make sure that AllocationSize plus OverAllocationSize does not overflow. \r
+ //\r
+ return NULL;\r
+ }\r
+ RawAddress = InternalAllocatePool (PoolType, RealAllocationSize);\r
+ if (RawAddress == NULL) {\r
return NULL;\r
}\r
AlignedAddress = ((UINTN) RawAddress + OverAllocationSize) & ~AlignmentMask;\r