MdeModulePkg/PerformanceLib: Add NULL pointer check

1. Add NULL pointer check for the "Guid" parameter
   when handle FPDT_DUAL_GUID_STRING_EVENT_TYPE.
2. Make the code logic in DxeCore/SmmCore/PeiPerformanceLib
   aligned when handle FPDT_DUAL_GUID_STRING_EVENT_TYPE.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Hao Wu <hao.a.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Hao Wu <hao.a.wu@intel.com>
This commit is contained in:
Dandan Bi 2018-06-27 12:37:19 +08:00 committed by Eric Dong
parent ecd0f8b12f
commit 981b7edc0e
3 changed files with 32 additions and 17 deletions

View File

@ -1111,14 +1111,13 @@ InsertFpdtRecord (
case PERF_EVENTSIGNAL_END_ID:
case PERF_CALLBACK_START_ID:
case PERF_CALLBACK_END_ID:
if (String == NULL) {
if (String == NULL || Guid == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Cache the event guid in string event record when PcdEdkiiFpdtStringRecordEnableOnly == TRUE
//
CopyGuid (&ModuleGuid, Guid);
StringPtr = String;
if (AsciiStrLen (String) == 0) {
StringPtr = "unknown name";
}
if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
FpdtRecordPtr.DualGuidStringEvent->Header.Type = FPDT_DUAL_GUID_STRING_EVENT_TYPE;
FpdtRecordPtr.DualGuidStringEvent->Header.Length = sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD);
@ -1196,7 +1195,14 @@ InsertFpdtRecord (
FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;
FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;
FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;
CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));
if (Guid != NULL) {
//
// Cache the event guid in string event record.
//
CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, Guid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));
} else {
CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));
}
if (AsciiStrLen (StringPtr) == 0) {
StringPtr = "unknown name";
}

View File

@ -77,10 +77,10 @@ GetFpdtRecordPtr (
//
PeiFirmwarePerformance = (UINT8*)GET_GUID_HOB_DATA (GuidHob);
*PeiPerformanceLogHeader = (FPDT_PEI_EXT_PERF_HEADER *)PeiFirmwarePerformance;
if (!(*PeiPerformanceLogHeader)->HobIsFull && (*PeiPerformanceLogHeader)->SizeOfAllEntries + RecordSize > (UINTN)(PeiPerformanceLogEntries * PEI_MAX_RECORD_SIZE)) {
if (!(*PeiPerformanceLogHeader)->HobIsFull && (*PeiPerformanceLogHeader)->SizeOfAllEntries + RecordSize > (PeiPerformanceLogEntries * PEI_MAX_RECORD_SIZE)) {
(*PeiPerformanceLogHeader)->HobIsFull = TRUE;
}
if (!(*PeiPerformanceLogHeader)->HobIsFull && (*PeiPerformanceLogHeader)->SizeOfAllEntries + RecordSize <= (UINTN)(PeiPerformanceLogEntries * PEI_MAX_RECORD_SIZE)) {
if (!(*PeiPerformanceLogHeader)->HobIsFull && (*PeiPerformanceLogHeader)->SizeOfAllEntries + RecordSize <= (PeiPerformanceLogEntries * PEI_MAX_RECORD_SIZE)) {
FpdtRecordPtr->RecordHeader = (EFI_ACPI_5_0_FPDT_PERFORMANCE_RECORD_HEADER *)(PeiFirmwarePerformance + sizeof (FPDT_PEI_EXT_PERF_HEADER) + (*PeiPerformanceLogHeader)->SizeOfAllEntries);
break;
}
@ -423,9 +423,11 @@ InsertFpdtRecord (
case PERF_EVENTSIGNAL_END_ID:
case PERF_CALLBACK_START_ID:
case PERF_CALLBACK_END_ID:
if (String != NULL && AsciiStrLen (String) != 0) {
StringPtr = String;
} else {
if (String == NULL || Guid == NULL) {
return EFI_INVALID_PARAMETER;
}
StringPtr = String;
if (AsciiStrLen (String) == 0) {
StringPtr = "unknown name";
}
if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
@ -436,6 +438,7 @@ InsertFpdtRecord (
FpdtRecordPtr.DualGuidStringEvent->Timestamp = TimeStamp;
CopyMem (&FpdtRecordPtr.DualGuidStringEvent->Guid1, ModuleGuid, sizeof (FpdtRecordPtr.DualGuidStringEvent->Guid1));
CopyMem (&FpdtRecordPtr.DualGuidStringEvent->Guid2, Guid, sizeof (FpdtRecordPtr.DualGuidStringEvent->Guid2));
CopyStringIntoPerfRecordAndUpdateLength (FpdtRecordPtr.DualGuidStringEvent->String, StringPtr, &FpdtRecordPtr.DualGuidStringEvent->Header.Length);
}
break;

View File

@ -649,14 +649,13 @@ InsertFpdtRecord (
case PERF_EVENTSIGNAL_END_ID:
case PERF_CALLBACK_START_ID:
case PERF_CALLBACK_END_ID:
if (String == NULL) {
if (String == NULL || Guid == NULL) {
return EFI_INVALID_PARAMETER;
}
//
// Cache the event guid in string event record when PcdEdkiiFpdtStringRecordEnableOnly == TRUE
//
CopyGuid (&ModuleGuid, Guid);
StringPtr = String;
if (AsciiStrLen (String) == 0) {
StringPtr = "unknown name";
}
if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) {
FpdtRecordPtr.DualGuidStringEvent->Header.Type = FPDT_DUAL_GUID_STRING_EVENT_TYPE;
FpdtRecordPtr.DualGuidStringEvent->Header.Length = sizeof (FPDT_DUAL_GUID_STRING_EVENT_RECORD);
@ -734,7 +733,14 @@ InsertFpdtRecord (
FpdtRecordPtr.DynamicStringEvent->Header.Revision = FPDT_RECORD_REVISION_1;
FpdtRecordPtr.DynamicStringEvent->ProgressID = PerfId;
FpdtRecordPtr.DynamicStringEvent->Timestamp = TimeStamp;
CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));
if (Guid != NULL) {
//
// Cache the event guid in string event record.
//
CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, Guid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));
} else {
CopyMem (&FpdtRecordPtr.DynamicStringEvent->Guid, &ModuleGuid, sizeof (FpdtRecordPtr.DynamicStringEvent->Guid));
}
if (AsciiStrLen (StringPtr) == 0) {
StringPtr = "unknown name";
}