summaryrefslogtreecommitdiff
path: root/MdePkg
diff options
context:
space:
mode:
authorniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>2011-06-09 02:51:00 +0000
committerniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>2011-06-09 02:51:00 +0000
commitef2635c399770673375249722ae1e121db1e9ad1 (patch)
treecd69b8f8e39c811a8ff3a9468aafb04981defd68 /MdePkg
parent10fe0d814add860a1040e648b1f5782c0de350e6 (diff)
downloadedk2-platforms-ef2635c399770673375249722ae1e121db1e9ad1.tar.xz
Change BuildGuidHob and BuildGuidDataHob to return NULL upon failure.
Guarantee no memory corruption in an out of memory condition even in production builds. Signed-off-by: niruiyu Reviewed-by: mdkinney git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11775 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdePkg')
-rw-r--r--MdePkg/Include/Library/HobLib.h8
-rw-r--r--MdePkg/Library/DxeCoreHobLib/HobLib.c8
-rw-r--r--MdePkg/Library/DxeHobLib/HobLib.c8
-rw-r--r--MdePkg/Library/PeiHobLib/HobLib.c54
4 files changed, 64 insertions, 14 deletions
diff --git a/MdePkg/Include/Library/HobLib.h b/MdePkg/Include/Library/HobLib.h
index a7bc26a742..8af7fbe0e1 100644
--- a/MdePkg/Include/Library/HobLib.h
+++ b/MdePkg/Include/Library/HobLib.h
@@ -8,7 +8,7 @@
allows the PEI phase to pass information to the DXE phase. HOBs are position
independent and can be relocated easily to different memory memory locations.
-Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -225,7 +225,8 @@ BuildResourceDescriptorHob (
@param Guid The GUID to tag the customized HOB.
@param DataLength The size of the data payload for the GUID HOB.
- @return The start address of GUID HOB data.
+ @retval NULL The GUID HOB could not be allocated.
+ @retval others The start address of GUID HOB data.
**/
VOID *
@@ -255,7 +256,8 @@ BuildGuidHob (
@param Data The data to be copied into the data field of the GUID HOB.
@param DataLength The size of the data payload for the GUID HOB.
- @return The start address of GUID HOB data.
+ @retval NULL The GUID HOB could not be allocated.
+ @retval others The start address of GUID HOB data.
**/
VOID *
diff --git a/MdePkg/Library/DxeCoreHobLib/HobLib.c b/MdePkg/Library/DxeCoreHobLib/HobLib.c
index 9fdb2b448a..912f97d898 100644
--- a/MdePkg/Library/DxeCoreHobLib/HobLib.c
+++ b/MdePkg/Library/DxeCoreHobLib/HobLib.c
@@ -1,7 +1,7 @@
/** @file
HOB Library implementation for DxeCore driver.
-Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -286,7 +286,8 @@ BuildResourceDescriptorHob (
@param Guid The GUID to tag the customized HOB.
@param DataLength The size of the data payload for the GUID HOB.
- @return The start address of GUID HOB data.
+ @retval NULL The GUID HOB could not be allocated.
+ @retval others The start address of GUID HOB data.
**/
VOID *
@@ -323,7 +324,8 @@ BuildGuidHob (
@param Data The data to be copied into the data field of the GUID HOB.
@param DataLength The size of the data payload for the GUID HOB.
- @return The start address of GUID HOB data.
+ @retval NULL The GUID HOB could not be allocated.
+ @retval others The start address of GUID HOB data.
**/
VOID *
diff --git a/MdePkg/Library/DxeHobLib/HobLib.c b/MdePkg/Library/DxeHobLib/HobLib.c
index dfd4bed67a..3a015bb192 100644
--- a/MdePkg/Library/DxeHobLib/HobLib.c
+++ b/MdePkg/Library/DxeHobLib/HobLib.c
@@ -1,7 +1,7 @@
/** @file
HOB Library implemenation for Dxe Phase.
-Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -319,7 +319,8 @@ BuildResourceDescriptorHob (
@param Guid The GUID to tag the customized HOB.
@param DataLength The size of the data payload for the GUID HOB.
- @return The start address of GUID HOB data.
+ @retval NULL The GUID HOB could not be allocated.
+ @retval others The start address of GUID HOB data.
**/
VOID *
@@ -356,7 +357,8 @@ BuildGuidHob (
@param Data The data to be copied into the data field of the GUID HOB.
@param DataLength The size of the data payload for the GUID HOB.
- @return The start address of GUID HOB data.
+ @retval NULL The GUID HOB could not be allocated.
+ @retval others The start address of GUID HOB data.
**/
VOID *
diff --git a/MdePkg/Library/PeiHobLib/HobLib.c b/MdePkg/Library/PeiHobLib/HobLib.c
index 604cee996c..113de832fc 100644
--- a/MdePkg/Library/PeiHobLib/HobLib.c
+++ b/MdePkg/Library/PeiHobLib/HobLib.c
@@ -1,7 +1,7 @@
/** @file
Provide Hob Library functions for Pei phase.
-Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -226,7 +226,8 @@ GetBootModeHob (
@param Type Type of the new HOB.
@param Length Length of the new HOB to allocate.
- @return The address of new HOB.
+ @retval NULL The HOB could not be allocated.
+ @retval others The address of new HOB.
**/
VOID *
@@ -240,10 +241,13 @@ InternalPeiCreateHob (
VOID *Hob;
Status = PeiServicesCreateHob (Type, Length, &Hob);
+ if (EFI_ERROR (Status)) {
+ Hob = NULL;
+ }
//
// Assume the process of HOB building is always successful.
//
- ASSERT_EFI_ERROR (Status);
+ ASSERT (Hob != NULL);
return Hob;
}
@@ -278,6 +282,9 @@ BuildModuleHob (
((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0));
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE));
+ if (Hob == NULL) {
+ return;
+ }
CopyGuid (&(Hob->MemoryAllocationHeader.Name), &gEfiHobMemoryAllocModuleGuid);
Hob->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule;
@@ -320,6 +327,9 @@ BuildResourceDescriptorHob (
EFI_HOB_RESOURCE_DESCRIPTOR *Hob;
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, (UINT16) sizeof (EFI_HOB_RESOURCE_DESCRIPTOR));
+ if (Hob == NULL) {
+ return;
+ }
Hob->ResourceType = ResourceType;
Hob->ResourceAttribute = ResourceAttribute;
@@ -344,7 +354,8 @@ BuildResourceDescriptorHob (
@param Guid The GUID to tag the customized HOB.
@param DataLength The size of the data payload for the GUID HOB.
- @return The start address of GUID HOB data.
+ @retval NULL The GUID HOB could not be allocated.
+ @retval others The start address of GUID HOB data.
**/
VOID *
@@ -357,11 +368,19 @@ BuildGuidHob (
EFI_HOB_GUID_TYPE *Hob;
//
+ // Make sure Guid is valid
+ //
+ ASSERT (Guid != NULL);
+
+ //
// Make sure that data length is not too long.
//
ASSERT (DataLength <= (0xffff - sizeof (EFI_HOB_GUID_TYPE)));
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof (EFI_HOB_GUID_TYPE) + DataLength));
+ if (Hob == NULL) {
+ return Hob;
+ }
CopyGuid (&Hob->Name, Guid);
return Hob + 1;
}
@@ -386,7 +405,8 @@ BuildGuidHob (
@param Data The data to be copied into the data field of the GUID HOB.
@param DataLength The size of the data payload for the GUID HOB.
- @return The start address of GUID HOB data.
+ @retval NULL The GUID HOB could not be allocated.
+ @retval others The start address of GUID HOB data.
**/
VOID *
@@ -402,6 +422,9 @@ BuildGuidDataHob (
ASSERT (Data != NULL || DataLength == 0);
HobData = BuildGuidHob (Guid, DataLength);
+ if (HobData == NULL) {
+ return HobData;
+ }
return CopyMem (HobData, Data, DataLength);
}
@@ -429,6 +452,9 @@ BuildFvHob (
EFI_HOB_FIRMWARE_VOLUME *Hob;
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME));
+ if (Hob == NULL) {
+ return;
+ }
Hob->BaseAddress = BaseAddress;
Hob->Length = Length;
@@ -461,6 +487,9 @@ BuildFv2Hob (
EFI_HOB_FIRMWARE_VOLUME2 *Hob;
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_FV2, (UINT16) sizeof (EFI_HOB_FIRMWARE_VOLUME2));
+ if (Hob == NULL) {
+ return;
+ }
Hob->BaseAddress = BaseAddress;
Hob->Length = Length;
@@ -492,6 +521,9 @@ BuildCvHob (
EFI_HOB_UEFI_CAPSULE *Hob;
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_UEFI_CAPSULE, (UINT16) sizeof (EFI_HOB_UEFI_CAPSULE));
+ if (Hob == NULL) {
+ return;
+ }
Hob->BaseAddress = BaseAddress;
Hob->Length = Length;
@@ -520,6 +552,9 @@ BuildCpuHob (
EFI_HOB_CPU *Hob;
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_CPU, (UINT16) sizeof (EFI_HOB_CPU));
+ if (Hob == NULL) {
+ return;
+ }
Hob->SizeOfMemorySpace = SizeOfMemorySpace;
Hob->SizeOfIoSpace = SizeOfIoSpace;
@@ -556,6 +591,9 @@ BuildStackHob (
((Length & (EFI_PAGE_SIZE - 1)) == 0));
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK));
+ if (Hob == NULL) {
+ return;
+ }
CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);
Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
@@ -596,6 +634,9 @@ BuildBspStoreHob (
((Length & (EFI_PAGE_SIZE - 1)) == 0));
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE));
+ if (Hob == NULL) {
+ return;
+ }
CopyGuid (&(Hob->AllocDescriptor.Name), &gEfiHobMemoryAllocBspStoreGuid);
Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;
@@ -636,6 +677,9 @@ BuildMemoryAllocationHob (
((Length & (EFI_PAGE_SIZE - 1)) == 0));
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, (UINT16) sizeof (EFI_HOB_MEMORY_ALLOCATION));
+ if (Hob == NULL) {
+ return;
+ }
ZeroMem (&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID));
Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;