Add conformance check for OldBuffer and size even if the memory allocation fails.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8294 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qhuang8
2009-05-11 08:23:26 +00:00
parent 2842d31b8f
commit 446b94b0a1
4 changed files with 36 additions and 24 deletions

View File

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

View File

@ -84,7 +84,7 @@ AllocateReservedPages (
Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
must have been allocated on a previous call to the page allocation services of the Memory must have been allocated on a previous call to the page allocation services of the Memory
Allocation Library. If it is not possible to free allocated pages, then this function will Allocation Library. If it is not possible to free allocated pages, then this function will
peform no actions. perform no actions.
If Buffer was not allocated with a page allocation function in the Memory Allocation Library, If Buffer was not allocated with a page allocation function in the Memory Allocation Library,
then ASSERT(). then ASSERT().
@ -180,7 +180,7 @@ AllocateAlignedReservedPages (
Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer Frees the number of 4KB pages specified by Pages from the buffer specified by Buffer. Buffer
must have been allocated on a previous call to the aligned page allocation services of the Memory must have been allocated on a previous call to the aligned page allocation services of the Memory
Allocation Library. If it is not possible to free allocated pages, then this function will Allocation Library. If it is not possible to free allocated pages, then this function will
peform no actions. perform no actions.
If Buffer was not allocated with an aligned page allocation function in the Memory Allocation If Buffer was not allocated with an aligned page allocation function in the Memory Allocation
Library, then ASSERT(). Library, then ASSERT().
@ -473,7 +473,7 @@ ReallocateReservedPool (
Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the Frees the buffer specified by Buffer. Buffer must have been allocated on a previous call to the
pool allocation services of the Memory Allocation Library. If it is not possible to free pool pool allocation services of the Memory Allocation Library. If it is not possible to free pool
resources, then this function will peform no actions. resources, then this function will perform no actions.
If Buffer was not allocated with a pool allocation function in the Memory Allocation Library, If Buffer was not allocated with a pool allocation function in the Memory Allocation Library,
then ASSERT(). then ASSERT().

View File

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

View File

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