summaryrefslogtreecommitdiff
path: root/IntelFrameworkModulePkg/Library
diff options
context:
space:
mode:
authorvanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>2010-11-10 06:12:25 +0000
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>2010-11-10 06:12:25 +0000
commitcd73414527f71295966afe5c046a48bbabf18766 (patch)
tree8787f593b74264aeea3907a120f7bdc5b849a690 /IntelFrameworkModulePkg/Library
parent7018623cd400d69848b94acb6008bf223cb75204 (diff)
downloadedk2-platforms-cd73414527f71295966afe5c046a48bbabf18766.tar.xz
Prevent infinite recursion when ASSERT(), DEBUG(), or any other use of ReportStatusCode is performed at > TPL_NOTIFY or there is not enough memory to allocate a buffer for the ExtendedData associated with the status code being reported.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11022 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'IntelFrameworkModulePkg/Library')
-rw-r--r--IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/ReportStatusCodeLib.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/ReportStatusCodeLib.c b/IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/ReportStatusCodeLib.c
index cf1f74c26c..af788cd4c9 100644
--- a/IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/ReportStatusCodeLib.c
+++ b/IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/ReportStatusCodeLib.c
@@ -487,6 +487,8 @@ ReportStatusCodeEx (
{
EFI_STATUS Status;
EFI_STATUS_CODE_DATA *StatusCodeData;
+ EFI_TPL Tpl;
+ UINT64 Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE / sizeof (UINT64)];
ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));
ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));
@@ -496,12 +498,32 @@ ReportStatusCodeEx (
}
//
- // Allocate space for the Status Code Header and its buffer
+ // Retrieve the current TPL
//
+ Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);
+ gBS->RestoreTPL (Tpl);
+
StatusCodeData = NULL;
- gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);
+ if (Tpl <= TPL_NOTIFY) {
+ //
+ // Allocate space for the Status Code Header and its buffer
+ //
+ gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);
+ }
+
if (StatusCodeData == NULL) {
- return EFI_OUT_OF_RESOURCES;
+ //
+ // If a buffer could not be allocated, then see if the local variable Buffer can be used
+ //
+ if (ExtendedDataSize > (EFI_STATUS_CODE_DATA_MAX_SIZE - sizeof (EFI_STATUS_CODE_DATA))) {
+ //
+ // The local variable Buffer not large enough to hold the extended data associated
+ // with the status code being reported.
+ //
+ ASSERT (FALSE);
+ return EFI_OUT_OF_RESOURCES;
+ }
+ StatusCodeData = (EFI_STATUS_CODE_DATA *)Buffer;
}
//
@@ -532,7 +554,9 @@ ReportStatusCodeEx (
//
// Free the allocated buffer
//
- gBS->FreePool (StatusCodeData);
+ if (StatusCodeData != (EFI_STATUS_CODE_DATA *)Buffer) {
+ gBS->FreePool (StatusCodeData);
+ }
return Status;
}