]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add conformance check for OldBuffer and size even if the memory allocation fails.
authorqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 11 May 2009 08:23:26 +0000 (08:23 +0000)
committerqhuang8 <qhuang8@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 11 May 2009 08:23:26 +0000 (08:23 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8294 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Library/DxeCoreMemoryAllocationLib/MemoryAllocationLib.c
MdePkg/Include/Library/MemoryAllocationLib.h
MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
MdePkg/Library/UefiMemoryAllocationLib/MemoryAllocationLib.c

index 641797cf1ebef529321be6664130010e1a131354..5939f2278c1a2cf5168aa0b20658224c3cfb4582 100644 (file)
@@ -128,7 +128,7 @@ AllocateReservedPages (
   Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer\r
   must have been allocated on a previous call to the page allocation services of the Memory\r
   Allocation Library.  If it is not possible to free allocated pages, then this function will\r
-  peform no actions.\r
+  perform no actions.\r
   \r
   If Buffer was not allocated with a page allocation function in the Memory Allocation Library,\r
   then ASSERT().\r
@@ -325,7 +325,7 @@ AllocateAlignedReservedPages (
   Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer\r
   must have been allocated on a previous call to the aligned page allocation services of the Memory\r
   Allocation Library.  If it is not possible to free allocated pages, then this function will \r
-  peform no actions.\r
+  perform no actions.\r
   \r
   If Buffer was not allocated with an aligned page allocation function in the Memory Allocation\r
   Library, then ASSERT().\r
@@ -442,9 +442,9 @@ AllocateReservedPool (
 }\r
 \r
 /**\r
-  Allocates and zeros a buffer of a certian pool type.\r
+  Allocates and zeros a buffer of a certain pool type.\r
 \r
-  Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type, clears the buffer\r
   with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a valid\r
   buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the request,\r
   then NULL is returned.\r
@@ -537,9 +537,9 @@ AllocateReservedZeroPool (
 }\r
 \r
 /**\r
-  Copies a buffer to an allocated buffer of a certian pool type.\r
+  Copies a buffer to an allocated buffer of a certain pool type.\r
 \r
-  Allocates the number bytes specified by AllocationSize of a certian pool type, copies\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type, copies\r
   AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
   allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
   is not enough memory remaining to satisfy the request, then NULL is returned.\r
@@ -685,6 +685,10 @@ InternalReallocatePool (
 {\r
   VOID  *NewBuffer;\r
 \r
+  //\r
+  // Check the boundary for OldBuffer even if the allocation failure.\r
+  //\r
+  ASSERT (OldBuffer == NULL || MIN (OldSize, NewSize) <= MAX_ADDRESS - (UINTN) OldBuffer + 1);\r
   NewBuffer = InternalAllocateZeroPool (PoolType, NewSize);\r
   if (NewBuffer != NULL && OldBuffer != NULL) {\r
     CopyMem (NewBuffer, OldBuffer, MIN (OldSize, NewSize));\r
@@ -795,7 +799,7 @@ ReallocateReservedPool (
 \r
   Frees the buffer specified by Buffer.  Buffer must have been allocated on a previous call to the\r
   pool allocation services of the Memory Allocation Library.  If it is not possible to free pool\r
-  resources, then this function will peform no actions.\r
+  resources, then this function will perform no actions.\r
   \r
   If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,\r
   then ASSERT().\r
index 8cc93f2bae663280aedd80ba20e786795eb1506c..597aeecaefd607531b1daa6986654b474f7b91b7 100644 (file)
@@ -84,7 +84,7 @@ AllocateReservedPages (
   Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer\r
   must have been allocated on a previous call to the page allocation services of the Memory\r
   Allocation Library.  If it is not possible to free allocated pages, then this function will\r
-  peform no actions.\r
+  perform no actions.\r
   \r
   If Buffer was not allocated with a page allocation function in the Memory Allocation Library,\r
   then ASSERT().\r
@@ -180,7 +180,7 @@ AllocateAlignedReservedPages (
   Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer\r
   must have been allocated on a previous call to the aligned page allocation services of the Memory\r
   Allocation Library.  If it is not possible to free allocated pages, then this function will \r
-  peform no actions.\r
+  perform no actions.\r
   \r
   If Buffer was not allocated with an aligned page allocation function in the Memory Allocation\r
   Library, then ASSERT().\r
@@ -473,7 +473,7 @@ ReallocateReservedPool (
 \r
   Frees the buffer specified by Buffer.  Buffer must have been allocated on a previous call to the\r
   pool allocation services of the Memory Allocation Library.  If it is not possible to free pool\r
-  resources, then this function will peform no actions.\r
+  resources, then this function will perform no actions.\r
   \r
   If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,\r
   then ASSERT().\r
index 4e5f8fadd492be1943766624ccb8f638c563da71..6e0517fe4d9087a5f776b6a5b009386a258e8a21 100644 (file)
@@ -129,7 +129,7 @@ AllocateReservedPages (
   Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer\r
   must have been allocated on a previous call to the page allocation services of the Memory\r
   Allocation Library.  If it is not possible to free allocated pages, then this function will\r
-  peform no actions.\r
+  perform no actions.\r
   \r
   If Buffer was not allocated with a page allocation function in the Memory Allocation Library,\r
   then ASSERT().\r
@@ -291,7 +291,7 @@ AllocateAlignedReservedPages (
   Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer\r
   must have been allocated on a previous call to the aligned page allocation services of the Memory\r
   Allocation Library.  If it is not possible to free allocated pages, then this function will \r
-  peform no actions.\r
+  perform no actions.\r
   \r
   If Buffer was not allocated with an aligned page allocation function in the Memory Allocation\r
   Library, then ASSERT().\r
@@ -412,9 +412,9 @@ AllocateReservedPool (
 }\r
 \r
 /**\r
-  Allocates and zeros a buffer of a certian pool type.\r
+  Allocates and zeros a buffer of a certain pool type.\r
 \r
-  Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type, clears the buffer\r
   with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a valid\r
   buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the request,\r
   then NULL is returned.\r
@@ -513,9 +513,9 @@ AllocateReservedZeroPool (
 }\r
 \r
 /**\r
-  Copies a buffer to an allocated buffer of a certian pool type.\r
+  Copies a buffer to an allocated buffer of a certain pool type.\r
 \r
-  Allocates the number bytes specified by AllocationSize of a certian pool type, copies\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type, copies\r
   AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
   allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
   is not enough memory remaining to satisfy the request, then NULL is returned.\r
@@ -670,6 +670,10 @@ InternalReallocatePool (
 {\r
   VOID  *NewBuffer;\r
 \r
+  //\r
+  // Check the boundary for OldBuffer even if the allocation failure.\r
+  //\r
+  ASSERT (OldBuffer == NULL || MIN (OldSize, NewSize) <= MAX_ADDRESS - (UINTN) OldBuffer + 1);\r
   NewBuffer = InternalAllocateZeroPool (PoolType, NewSize);\r
   if (NewBuffer != NULL && OldBuffer != NULL) {\r
     CopyMem (NewBuffer, OldBuffer, MIN (OldSize, NewSize));\r
@@ -780,7 +784,7 @@ ReallocateReservedPool (
 \r
   Frees the buffer specified by Buffer.  Buffer must have been allocated on a previous call to the\r
   pool allocation services of the Memory Allocation Library.  If it is not possible to free pool\r
-  resources, then this function will peform no actions.\r
+  resources, then this function will perform no actions.\r
   \r
   If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,\r
   then ASSERT().\r
index 08bb2921abece60bd640755bcb4b7c0e5cdcb39f..668372223cfaeb7c58a63071504ad83f8c93f66f 100644 (file)
@@ -128,7 +128,7 @@ AllocateReservedPages (
   Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer\r
   must have been allocated on a previous call to the page allocation services of the Memory\r
   Allocation Library.  If it is not possible to free allocated pages, then this function will\r
-  peform no actions.\r
+  perform no actions.\r
   \r
   If Buffer was not allocated with a page allocation function in the Memory Allocation Library,\r
   then ASSERT().\r
@@ -325,7 +325,7 @@ AllocateAlignedReservedPages (
   Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer.  Buffer\r
   must have been allocated on a previous call to the aligned page allocation services of the Memory\r
   Allocation Library.  If it is not possible to free allocated pages, then this function will \r
-  peform no actions.\r
+  perform no actions.\r
   \r
   If Buffer was not allocated with an aligned page allocation function in the Memory Allocation\r
   Library, then ASSERT().\r
@@ -442,9 +442,9 @@ AllocateReservedPool (
 }\r
 \r
 /**\r
-  Allocates and zeros a buffer of a certian pool type.\r
+  Allocates and zeros a buffer of a certain pool type.\r
 \r
-  Allocates the number bytes specified by AllocationSize of a certian pool type, clears the buffer\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type, clears the buffer\r
   with zeros, and returns a pointer to the allocated buffer.  If AllocationSize is 0, then a valid\r
   buffer of 0 size is returned.  If there is not enough memory remaining to satisfy the request,\r
   then NULL is returned.\r
@@ -537,9 +537,9 @@ AllocateReservedZeroPool (
 }\r
 \r
 /**\r
-  Copies a buffer to an allocated buffer of a certian pool type.\r
+  Copies a buffer to an allocated buffer of a certain pool type.\r
 \r
-  Allocates the number bytes specified by AllocationSize of a certian pool type, copies\r
+  Allocates the number bytes specified by AllocationSize of a certain pool type, copies\r
   AllocationSize bytes from Buffer to the newly allocated buffer, and returns a pointer to the\r
   allocated buffer.  If AllocationSize is 0, then a valid buffer of 0 size is returned.  If there\r
   is not enough memory remaining to satisfy the request, then NULL is returned.\r
@@ -685,6 +685,10 @@ InternalReallocatePool (
 {\r
   VOID  *NewBuffer;\r
 \r
+  //\r
+  // Check the boundary for OldBuffer even if the allocation failure.\r
+  //\r
+  ASSERT (OldBuffer == NULL || MIN (OldSize, NewSize) <= MAX_ADDRESS - (UINTN) OldBuffer + 1);\r
   NewBuffer = InternalAllocateZeroPool (PoolType, NewSize);\r
   if (NewBuffer != NULL && OldBuffer != NULL) {\r
     CopyMem (NewBuffer, OldBuffer, MIN (OldSize, NewSize));\r
@@ -795,7 +799,7 @@ ReallocateReservedPool (
 \r
   Frees the buffer specified by Buffer.  Buffer must have been allocated on a previous call to the\r
   pool allocation services of the Memory Allocation Library.  If it is not possible to free pool\r
-  resources, then this function will peform no actions.\r
+  resources, then this function will perform no actions.\r
   \r
   If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,\r
   then ASSERT().\r