From 4de80843a74475aef3ac47127cec0e52c1f5aa46 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Fri, 27 Sep 2024 16:46:07 -0400 Subject: [PATCH] IntelFsp2WrapperPkg: Prevent null pointer dereference Return from `FspsWrapperInitDispatchMode()` if a buffer allocation fails instead of attempting to dereference the pointer. Signed-off-by: Michael Kubacki --- .../FspsWrapperPeim/FspsWrapperPeim.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.c b/IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.c index 1d4dd60577..62b5e45348 100644 --- a/IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.c +++ b/IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.c @@ -421,13 +421,22 @@ FspsWrapperInitDispatchMode ( EFI_PEI_PPI_DESCRIPTOR *MeasurementExcludedPpiList; MeasurementExcludedFvPpi = AllocatePool (sizeof (*MeasurementExcludedFvPpi)); - ASSERT (MeasurementExcludedFvPpi != NULL); + if (MeasurementExcludedFvPpi == NULL) { + ASSERT (MeasurementExcludedFvPpi != NULL); + return EFI_OUT_OF_RESOURCES; + } + MeasurementExcludedFvPpi->Count = 1; MeasurementExcludedFvPpi->Fv[0].FvBase = PcdGet32 (PcdFspsBaseAddress); MeasurementExcludedFvPpi->Fv[0].FvLength = ((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)PcdGet32 (PcdFspsBaseAddress))->FvLength; MeasurementExcludedPpiList = AllocatePool (sizeof (*MeasurementExcludedPpiList)); - ASSERT (MeasurementExcludedPpiList != NULL); + if (MeasurementExcludedPpiList == NULL) { + ASSERT (MeasurementExcludedPpiList != NULL); + FreePool (MeasurementExcludedFvPpi); + return EFI_OUT_OF_RESOURCES; + } + MeasurementExcludedPpiList->Flags = EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST; MeasurementExcludedPpiList->Guid = &gEfiPeiFirmwareVolumeInfoMeasurementExcludedPpiGuid; MeasurementExcludedPpiList->Ppi = MeasurementExcludedFvPpi;