From a8d58376ec8df8193d9dc723cfdcd3f913a81572 Mon Sep 17 00:00:00 2001 From: Michael Kubacki Date: Wed, 31 Jul 2024 16:12:03 -0700 Subject: [PATCH] MdeModulePkg: CodeQL Fixes. Includes changes across the repo for the following CodeQL rules: - cpp/comparison-with-wider-type - cpp/overflow-buffer - cpp/redundant-null-check-param - cpp/uselesstest Co-authored-by: Taylor Beebe Co-authored-by: pohanch <125842322+pohanch@users.noreply.github.com> Co-authored-by: kenlautner <85201046+kenlautner@users.noreply.github.com> Co-authored-by: Oliver Smith-Denny Co-authored-by: Sean Brogan Co-authored-by: Aaron Pop <105021049+apop5@users.noreply.github.com> Signed-off-by: Aaron Pop --- .../BootManagerMenuApp/BootManagerMenu.c | 113 +-- .../Application/CapsuleApp/CapsuleDump.c | 2 +- .../Application/CapsuleApp/CapsuleOnDisk.c | 6 +- .../SmiHandlerProfileInfo.c | 8 +- MdeModulePkg/Application/UiApp/FrontPage.c | 71 +- .../UiApp/FrontPageCustomizedUiSupport.c | 7 + .../Bus/Ata/AtaAtapiPassThru/IdeMode.c | 2 +- MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c | 2 +- .../NonDiscoverablePciDeviceIo.c | 10 +- .../Pci/NvmExpressDxe/NvmExpressPassthru.c | 6 +- .../Bus/Pci/NvmExpressPei/NvmExpressPeiHci.c | 10 +- .../Pci/NvmExpressPei/NvmExpressPeiPassThru.c | 4 +- .../Bus/Pci/PciBusDxe/PciEnumerator.c | 74 +- MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c | 3 + MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c | 60 +- .../Bus/Pci/PciBusDxe/PciOptionRomSupport.c | 4 +- .../Bus/Pci/PciBusDxe/PciResourceSupport.c | 225 +++--- .../Bus/Pci/PciHostBridgeDxe/PciHostBridge.c | 3 + MdeModulePkg/Bus/Pci/PciSioSerialDxe/Serial.c | 10 +- .../Bus/Pci/PciSioSerialDxe/SerialIo.c | 2 +- .../Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c | 10 +- .../Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h | 1 + .../Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf | 1 + .../Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c | 2 +- .../Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.c | 9 +- .../Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.h | 1 + .../Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.inf | 1 + MdeModulePkg/Bus/Pci/UhciPei/UhcPeim.c | 8 +- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 42 +- MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c | 2 + MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c | 6 +- .../Bus/Sd/EmmcBlockIoPei/EmmcHcMem.c | 1 + MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c | 2 +- MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHcMem.c | 1 + MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHcMem.c | 1 + MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c | 2 +- .../Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c | 2 +- MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c | 2 +- MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c | 16 +- MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c | 25 +- .../UsbMouseAbsolutePointer.c | 14 +- MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c | 24 +- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 45 +- MdeModulePkg/Core/Dxe/Hand/Handle.c | 3 +- MdeModulePkg/Core/Dxe/Image/Image.c | 10 +- MdeModulePkg/Core/Dxe/Mem/Page.c | 7 +- MdeModulePkg/Core/Dxe/Mem/Pool.c | 4 + .../Core/Dxe/Misc/MemoryAttributesTable.c | 12 +- .../SectionExtraction/CoreSectionExtraction.c | 5 +- .../Core/DxeIplPeim/X64/VirtualMemory.c | 15 +- MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c | 31 +- MdeModulePkg/Core/Pei/FwVol/FwVol.c | 4 +- MdeModulePkg/Core/Pei/Hob/Hob.c | 6 +- MdeModulePkg/Core/Pei/Ppi/Ppi.c | 15 +- .../Core/PiSmmCore/MemoryAttributesTable.c | 6 +- MdeModulePkg/Core/PiSmmCore/Page.c | 6 +- MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c | 57 +- .../Core/PiSmmCore/SmiHandlerProfile.c | 4 +- .../Core/PiSmmCore/SmramProfileRecord.c | 4 +- .../BootMaintenance.c | 80 +- ...ootMaintenanceManagerCustomizedUiSupport.c | 164 +++-- .../BootMaintenanceManagerUiLib/BootOption.c | 6 +- .../ConsoleOption.c | 76 +- .../BootMaintenanceManagerUiLib/UpdatePage.c | 14 +- .../BootMaintenanceManagerUiLib/Variable.c | 20 +- .../Library/BootManagerUiLib/BootManager.c | 188 ++--- .../BrotliDecompress.c | 6 +- .../CustomizedDisplayLibInternal.c | 4 +- .../DeviceManagerUiLib/DeviceManager.c | 344 ++++----- .../Library/DxeCapsuleLibFmp/CapsuleOnDisk.c | 2 +- .../DxeCorePerformanceLib.c | 48 +- .../DxeSecurityManagementLib.c | 19 +- .../Library/FileExplorerLib/FileExplorer.c | 11 +- .../SmmCorePerformanceLib.c | 24 +- .../Library/SmmLockBoxLib/SmmLockBoxMmLib.c | 22 +- .../Library/UefiBootManagerLib/BmBoot.c | 173 +++-- .../UefiBootManagerLib/BmBootDescription.c | 38 +- .../Library/UefiBootManagerLib/BmConsole.c | 58 +- .../UefiBootManagerLib/BmDriverHealth.c | 152 ++-- .../Library/UefiBootManagerLib/BmHotkey.c | 105 +-- .../Library/UefiBootManagerLib/BmLoadOption.c | 41 +- .../Library/UefiBootManagerLib/BmMisc.c | 5 +- MdeModulePkg/Library/UefiHiiLib/HiiLib.c | 98 ++- .../Library/UefiHiiLib/UefiHiiLib.inf | 1 + .../Library/UefiSortLib/UefiSortLib.c | 5 +- .../VarCheckHiiLib/VarCheckHiiGenFromFv.c | 2 + .../VarCheckPcdLib/VarCheckPcdLibNullClass.c | 2 + .../Universal/Acpi/AcpiTableDxe/AcpiSdt.c | 24 + .../Universal/Acpi/AcpiTableDxe/AcpiTable.c | 7 +- .../Acpi/AcpiTableDxe/AcpiTableProtocol.c | 4 + .../Acpi/AcpiTableDxe/AmlNamespace.c | 17 +- .../Universal/Acpi/AcpiTableDxe/AmlString.c | 8 +- MdeModulePkg/Universal/BdsDxe/BdsEntry.c | 48 +- .../Universal/CapsulePei/UefiCapsule.c | 2 +- .../Console/ConPlatformDxe/ConPlatform.c | 10 +- .../GraphicsConsoleDxe/GraphicsConsole.c | 14 +- .../Universal/Console/TerminalDxe/Terminal.c | 28 +- .../Universal/Disk/PartitionDxe/Mbr.c | 2 +- .../Universal/Disk/RamDiskDxe/RamDiskImpl.c | 146 ++-- .../Disk/RamDiskDxe/RamDiskProtocol.c | 7 +- .../Disk/UdfDxe/FileSystemOperations.c | 2 + .../EbcDxe/EbcDebugger/EdbCmdSymbol.c | 5 + MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmp.c | 36 +- .../Universal/FaultTolerantWriteDxe/FtwMisc.c | 2 +- .../FaultTolerantWritePei.c | 2 +- .../FvSimpleFileSystem.c | 5 + .../FvSimpleFileSystemEntryPoint.c | 6 +- .../HiiDatabaseDxe/ConfigKeywordHandler.c | 164 +++-- .../Universal/HiiDatabaseDxe/ConfigRouting.c | 140 +++- .../Universal/HiiDatabaseDxe/Database.c | 105 +-- MdeModulePkg/Universal/HiiDatabaseDxe/Font.c | 29 +- .../HiiDatabaseDxe/HiiDatabaseDxe.inf | 1 + MdeModulePkg/Universal/HiiDatabaseDxe/Image.c | 2 +- .../Universal/HiiDatabaseDxe/String.c | 21 +- MdeModulePkg/Universal/PCD/Dxe/Pcd.c | 17 +- MdeModulePkg/Universal/PCD/Dxe/Service.c | 88 ++- MdeModulePkg/Universal/PCD/Pei/Pcd.c | 91 ++- MdeModulePkg/Universal/PCD/Pei/Service.c | 31 +- .../PlatDriOverrideDxe.c | 21 +- .../PlatDriOverrideLib.c | 10 +- .../RegularExpressionDxe.c | 2 +- .../Smm/ReportStatusCodeRouterCommon.c | 4 + .../SectionExtractionPei.c | 15 +- .../Universal/SetupBrowserDxe/Expression.c | 72 +- .../Universal/SetupBrowserDxe/IfrParse.c | 686 ++++++++++++------ .../Universal/SetupBrowserDxe/Presentation.c | 151 ++-- .../Universal/SetupBrowserDxe/Setup.c | 467 +++++++----- .../SmmCommunicationBufferDxe.c | 5 + .../Universal/Variable/Pei/Variable.c | 2 +- .../Universal/Variable/RuntimeDxe/Variable.c | 124 ++-- .../RuntimeDxe/VariablePolicySmmDxe.c | 7 +- 131 files changed, 3507 insertions(+), 1860 deletions(-) diff --git a/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c b/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c index ef1931961432..47f32d5e8f41 100644 --- a/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c +++ b/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c @@ -1096,69 +1096,72 @@ BootManagerMenuEntry ( // Initialize Boot menu data // Status = InitializeBootMenuData (BootOption, BootOptionCount, &BootMenuData); - // - // According to boot menu data to draw boot popup menu - // - DrawBootPopupMenu (&BootMenuData); - // - // check user input to determine want to re-draw or boot from user selected item - // - ExitApplication = FALSE; - while (!ExitApplication) { - gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &Index); - Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); - if (!EFI_ERROR (Status)) { - switch (Key.UnicodeChar) { - case CHAR_NULL: - switch (Key.ScanCode) { - case SCAN_UP: - SelectItem = BootMenuData.SelectItem == 0 ? BootMenuData.ItemCount - 1 : BootMenuData.SelectItem - 1; - BootMenuSelectItem (SelectItem, &BootMenuData); - break; - - case SCAN_DOWN: - SelectItem = BootMenuData.SelectItem == BootMenuData.ItemCount - 1 ? 0 : BootMenuData.SelectItem + 1; - BootMenuSelectItem (SelectItem, &BootMenuData); - break; - - case SCAN_ESC: - gST->ConOut->ClearScreen (gST->ConOut); - ExitApplication = TRUE; - // - // Set boot resolution for normal boot - // - BdsSetConsoleMode (FALSE); - break; + if (!EFI_ERROR (Status)) { + // + // According to boot menu data to draw boot popup menu + // + DrawBootPopupMenu (&BootMenuData); - default: - break; - } + // + // check user input to determine want to re-draw or boot from user selected item + // + ExitApplication = FALSE; + while (!ExitApplication) { + gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &Index); + Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); + if (!EFI_ERROR (Status)) { + switch (Key.UnicodeChar) { + case CHAR_NULL: + switch (Key.ScanCode) { + case SCAN_UP: + SelectItem = BootMenuData.SelectItem == 0 ? BootMenuData.ItemCount - 1 : BootMenuData.SelectItem - 1; + BootMenuSelectItem (SelectItem, &BootMenuData); + break; + + case SCAN_DOWN: + SelectItem = BootMenuData.SelectItem == BootMenuData.ItemCount - 1 ? 0 : BootMenuData.SelectItem + 1; + BootMenuSelectItem (SelectItem, &BootMenuData); + break; + + case SCAN_ESC: + gST->ConOut->ClearScreen (gST->ConOut); + ExitApplication = TRUE; + // + // Set boot resolution for normal boot + // + BdsSetConsoleMode (FALSE); + break; + + default: + break; + } - break; + break; - case CHAR_CARRIAGE_RETURN: - gST->ConOut->ClearScreen (gST->ConOut); - // - // Set boot resolution for normal boot - // - BdsSetConsoleMode (FALSE); - BootFromSelectOption (BootOption, BootOptionCount, BootMenuData.SelectItem); - // - // Back to boot manager menu again, set back to setup resolution - // - BdsSetConsoleMode (TRUE); - DrawBootPopupMenu (&BootMenuData); - break; + case CHAR_CARRIAGE_RETURN: + gST->ConOut->ClearScreen (gST->ConOut); + // + // Set boot resolution for normal boot + // + BdsSetConsoleMode (FALSE); + BootFromSelectOption (BootOption, BootOptionCount, BootMenuData.SelectItem); + // + // Back to boot manager menu again, set back to setup resolution + // + BdsSetConsoleMode (TRUE); + DrawBootPopupMenu (&BootMenuData); + break; - default: - break; + default: + break; + } } } - } - EfiBootManagerFreeLoadOptions (BootOption, BootOptionCount); - FreePool (BootMenuData.PtrTokens); + EfiBootManagerFreeLoadOptions (BootOption, BootOptionCount); + FreePool (BootMenuData.PtrTokens); + } HiiRemovePackages (gStringPackHandle); diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c index 7605153e972b..b218e00d1b3c 100644 --- a/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleDump.c @@ -993,7 +993,7 @@ DumpProvisionedCapsule ( // // Display description and device path // - GetEfiSysPartitionFromBootOptionFilePath (BootNextOptionEntry.FilePath, &DevicePath, &Fs); + Status = GetEfiSysPartitionFromBootOptionFilePath (BootNextOptionEntry.FilePath, &DevicePath, &Fs); if (!EFI_ERROR (Status)) { Print (L"Capsules are provisioned on BootOption: %s\n", BootNextOptionEntry.Description); Print (L" %s %s\n", ShellProtocol->GetMapFromDevicePath (&DevicePath), ConvertDevicePathToText (DevicePath, TRUE, TRUE)); diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c index 5ce5a50f7b96..f1501ebcf4d8 100644 --- a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c +++ b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c @@ -518,7 +518,11 @@ GetUpdateFileSystem ( // If map is assigned, try to get ESP from mapped Fs. // DevicePath = DuplicateDevicePath (MappedDevicePath); - Status = GetEfiSysPartitionFromDevPath (DevicePath, &FullPath, Fs); + if (DevicePath == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Status = GetEfiSysPartitionFromDevPath (DevicePath, &FullPath, Fs); if (EFI_ERROR (Status)) { Print (L"Error: Cannot get EFI system partition from '%s' - %r\n", Map, Status); return EFI_NOT_FOUND; diff --git a/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c index 68c2e357917b..ea053a94a879 100644 --- a/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c +++ b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c @@ -610,7 +610,13 @@ DumpSmiHandler ( Print (L">\n"); ImageStruct = GetImageFromRef ((UINTN)SmiHandlerStruct->ImageRef); - NameString = GetDriverNameString (ImageStruct); + // If ImageStruct returned NULL, initialize NameString to an empty string + if (ImageStruct != NULL) { + NameString = GetDriverNameString (ImageStruct); + } else { + NameString = "\0"; + } + Print (L" \n", SmiHandlerStruct->ImageRef, NameString); if ((ImageStruct != NULL) && (ImageStruct->PdbStringOffset != 0)) { Print (L" %a\n", (UINT8 *)ImageStruct + ImageStruct->PdbStringOffset); diff --git a/MdeModulePkg/Application/UiApp/FrontPage.c b/MdeModulePkg/Application/UiApp/FrontPage.c index 0e784fb327f5..2094032d8b7a 100644 --- a/MdeModulePkg/Application/UiApp/FrontPage.c +++ b/MdeModulePkg/Application/UiApp/FrontPage.c @@ -205,40 +205,43 @@ UpdateFrontPageForm ( // StartOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (StartOpCodeHandle != NULL); + if (StartOpCodeHandle != NULL) { + EndOpCodeHandle = HiiAllocateOpCodeHandle (); + ASSERT (EndOpCodeHandle != NULL); + if (EndOpCodeHandle != NULL) { + // + // Create Hii Extend Label OpCode as the start opcode + // + StartGuidLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); + StartGuidLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + StartGuidLabel->Number = LABEL_FRONTPAGE_INFORMATION; + // + // Create Hii Extend Label OpCode as the end opcode + // + EndGuidLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); + EndGuidLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + EndGuidLabel->Number = LABEL_END; - EndOpCodeHandle = HiiAllocateOpCodeHandle (); - ASSERT (EndOpCodeHandle != NULL); - // - // Create Hii Extend Label OpCode as the start opcode - // - StartGuidLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); - StartGuidLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; - StartGuidLabel->Number = LABEL_FRONTPAGE_INFORMATION; - // - // Create Hii Extend Label OpCode as the end opcode - // - EndGuidLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); - EndGuidLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; - EndGuidLabel->Number = LABEL_END; - - // - // Updata Front Page form - // - UiCustomizeFrontPage ( - gFrontPagePrivate.HiiHandle, - StartOpCodeHandle - ); - - HiiUpdateForm ( - gFrontPagePrivate.HiiHandle, - &mFrontPageGuid, - FRONT_PAGE_FORM_ID, - StartOpCodeHandle, - EndOpCodeHandle - ); + // + // Updata Front Page form + // + UiCustomizeFrontPage ( + gFrontPagePrivate.HiiHandle, + StartOpCodeHandle + ); + + HiiUpdateForm ( + gFrontPagePrivate.HiiHandle, + &mFrontPageGuid, + FRONT_PAGE_FORM_ID, + StartOpCodeHandle, + EndOpCodeHandle + ); + HiiFreeOpCodeHandle (EndOpCodeHandle); + } - HiiFreeOpCodeHandle (StartOpCodeHandle); - HiiFreeOpCodeHandle (EndOpCodeHandle); + HiiFreeOpCodeHandle (StartOpCodeHandle); + } } /** @@ -976,7 +979,9 @@ InitializeUserInterface ( UiSetConsoleMode (FALSE); UninitializeStringSupport (); - HiiRemovePackages (HiiHandle); + if (HiiHandle != NULL) { + HiiRemovePackages (HiiHandle); + } return EFI_SUCCESS; } diff --git a/MdeModulePkg/Application/UiApp/FrontPageCustomizedUiSupport.c b/MdeModulePkg/Application/UiApp/FrontPageCustomizedUiSupport.c index 8bc7883bb79d..1d872fe3e0dd 100644 --- a/MdeModulePkg/Application/UiApp/FrontPageCustomizedUiSupport.c +++ b/MdeModulePkg/Application/UiApp/FrontPageCustomizedUiSupport.c @@ -191,6 +191,11 @@ UiSupportLibCallbackHandler ( if (Action == EFI_BROWSER_ACTION_RETRIEVE) { if (QuestionId == FRONT_PAGE_KEY_LANGUAGE) { + if (Value == NULL) { + *Status = EFI_INVALID_PARAMETER; + return FALSE; + } + Value->u8 = gCurrentLanguageIndex; *Status = EFI_SUCCESS; } else { @@ -517,6 +522,8 @@ RequiredDriver ( UINTN TempSize; BOOLEAN RetVal; + Buffer = NULL; + Status = HiiGetFormSetFromHiiHandle (HiiHandle, &Buffer, &BufferSize); if (EFI_ERROR (Status)) { return FALSE; diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c index 19d7b4930cb7..f475cadcb522 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c @@ -943,7 +943,7 @@ AtaPioDataInOut ( IN ATA_NONBLOCK_TASK *Task ) { - UINTN WordCount; + UINT64 WordCount; UINTN Increment; UINT16 *Buffer16; EFI_STATUS Status; diff --git a/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c b/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c index 3f5462c257aa..fb5dac616822 100644 --- a/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c +++ b/MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c @@ -563,7 +563,7 @@ AtapiEnumerateDevices ( // // Using Command and Control Regs Base Address to fill other registers. // - for (Index1 = 0; Index1 < IdeEnabledNumber; Index1++) { + for (Index1 = 0; (UINT32)Index1 < IdeEnabledNumber; Index1++) { CommandBlockBaseAddr = IdeRegsBaseAddr[Index1].CommandBlockBaseAddr; AtapiBlkIoDev->IdeIoPortReg[Index1].Data = CommandBlockBaseAddr; AtapiBlkIoDev->IdeIoPortReg[Index1].Reg1.Feature = (UINT16)(CommandBlockBaseAddr + 0x1); diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c index 4daf51761ba0..024a7f07d9f6 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceIo.c @@ -289,6 +289,7 @@ PciIoMemRead ( EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; EFI_STATUS Status; + Desc = NULL; if (Buffer == NULL) { return EFI_INVALID_PARAMETER; } @@ -377,6 +378,8 @@ PciIoMemWrite ( EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc; EFI_STATUS Status; + Desc = NULL; + if (Buffer == NULL) { return EFI_INVALID_PARAMETER; } @@ -1111,7 +1114,8 @@ NonCoherentPciIoAllocateBuffer ( NON_DISCOVERABLE_DEVICE_UNCACHED_ALLOCATION *Alloc; VOID *AllocAddress; - MemType = EFI_MEMORY_XP; + MemType = EFI_MEMORY_XP; + AllocAddress = NULL; if (HostAddress == NULL) { return EFI_INVALID_PARAMETER; @@ -1273,6 +1277,8 @@ NonCoherentPciIoMap ( EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor; BOOLEAN Bounce; + AllocAddress = NULL; + if ((HostAddress == NULL) || (NumberOfBytes == NULL) || (DeviceAddress == NULL) || @@ -1640,6 +1646,8 @@ PciIoGetBarAttributes ( EFI_ACPI_END_TAG_DESCRIPTOR *End; EFI_STATUS Status; + BarDesc = NULL; + if ((Supports == NULL) && (Resources == NULL)) { return EFI_INVALID_PARAMETER; } diff --git a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c index f818e48fc16d..60d984a99853 100644 --- a/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c +++ b/MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c @@ -219,10 +219,10 @@ NvmeCreatePrpList ( OUT VOID **Mapping ) { - UINTN PrpEntryNo; + UINT64 PrpEntryNo; UINT64 PrpListBase; - UINTN PrpListIndex; - UINTN PrpEntryIndex; + UINT64 PrpListIndex; + UINT64 PrpEntryIndex; UINT64 Remainder; EFI_PHYSICAL_ADDRESS PrpListPhyAddr; UINTN Bytes; diff --git a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiHci.c b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiHci.c index fc7b684940d9..e8580fcd395a 100644 --- a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiHci.c +++ b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiHci.c @@ -564,14 +564,16 @@ NvmeControllerInit ( // // Dump the NVME controller implementation version // - NVME_GET_VER (Private, &Ver); - DEBUG ((DEBUG_INFO, "NVME controller implementation version: %d.%d\n", Ver.Mjr, Ver.Mnr)); + Status = NVME_GET_VER (Private, &Ver); + if (!EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "NVME controller implementation version: %d.%d\n", Ver.Mjr, Ver.Mnr)); + } // // Read the controller Capabilities register and verify that the NVM command set is supported // - NVME_GET_CAP (Private, &Private->Cap); - if ((Private->Cap.Css & BIT0) == 0) { + Status = NVME_GET_CAP (Private, &Private->Cap); + if ( !EFI_ERROR (Status) && ((Private->Cap.Css & BIT0) == 0)) { DEBUG ((DEBUG_ERROR, "%a: The NVME controller doesn't support NVMe command set.\n", __func__)); return EFI_UNSUPPORTED; } diff --git a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiPassThru.c b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiPassThru.c index ac9328047fef..86608fdb630e 100644 --- a/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiPassThru.c +++ b/MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiPassThru.c @@ -27,12 +27,12 @@ NvmeCreatePrpList ( IN UINTN Pages ) { - UINTN PrpEntryNo; + UINT64 PrpEntryNo; UINTN PrpListNo; UINT64 PrpListBase; VOID *PrpListHost; UINTN PrpListIndex; - UINTN PrpEntryIndex; + UINT64 PrpEntryIndex; UINT64 Remainder; EFI_PHYSICAL_ADDRESS PrpListPhyAddr; UINTN Bytes; diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c index 3f8c6e6da7dc..74fc02af6362 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumerator.c @@ -881,7 +881,9 @@ GetMaxResourceConsumerDevice ( && (Temp->ResourceUsage != PciResUsagePadding)) { PPBResNode = GetMaxResourceConsumerDevice (Temp); - PciResNode = GetLargerConsumerDevice (PciResNode, PPBResNode); + if (PPBResNode != NULL) { + PciResNode = GetLargerConsumerDevice (PciResNode, PPBResNode); + } } else { PciResNode = GetLargerConsumerDevice (PciResNode, Temp); } @@ -1445,6 +1447,12 @@ PciBridgeResourceAllocator ( UINT64 PMem64Base; EFI_STATUS Status; + IoBridge = NULL; + Mem32Bridge = NULL; + PMem32Bridge = NULL; + Mem64Bridge = NULL; + PMem64Bridge = NULL; + IoBridge = CreateResourceNode ( Bridge, 0, @@ -1453,6 +1461,9 @@ PciBridgeResourceAllocator ( PciBarTypeIo16, PciResUsageTypical ); + if (IoBridge == NULL) { + goto CleanupAndExit; + } Mem32Bridge = CreateResourceNode ( Bridge, @@ -1462,6 +1473,9 @@ PciBridgeResourceAllocator ( PciBarTypeMem32, PciResUsageTypical ); + if (Mem32Bridge == NULL) { + goto CleanupAndExit; + } PMem32Bridge = CreateResourceNode ( Bridge, @@ -1471,6 +1485,9 @@ PciBridgeResourceAllocator ( PciBarTypePMem32, PciResUsageTypical ); + if (PMem32Bridge == NULL) { + goto CleanupAndExit; + } Mem64Bridge = CreateResourceNode ( Bridge, @@ -1480,6 +1497,9 @@ PciBridgeResourceAllocator ( PciBarTypeMem64, PciResUsageTypical ); + if (Mem64Bridge == NULL) { + goto CleanupAndExit; + } PMem64Bridge = CreateResourceNode ( Bridge, @@ -1489,6 +1509,9 @@ PciBridgeResourceAllocator ( PciBarTypePMem64, PciResUsageTypical ); + if (PMem64Bridge == NULL) { + goto CleanupAndExit; + } // // Create resourcemap by going through all the devices subject to this root bridge @@ -1512,7 +1535,7 @@ PciBridgeResourceAllocator ( ); if (EFI_ERROR (Status)) { - return Status; + goto CleanupAndExit; } // @@ -1555,17 +1578,32 @@ PciBridgeResourceAllocator ( PMem64Bridge ); - DestroyResourceTree (IoBridge); - DestroyResourceTree (Mem32Bridge); - DestroyResourceTree (PMem32Bridge); - DestroyResourceTree (PMem64Bridge); - DestroyResourceTree (Mem64Bridge); +CleanupAndExit: + + if (IoBridge != NULL) { + DestroyResourceTree (IoBridge); + gBS->FreePool (IoBridge); + } + + if (Mem32Bridge != NULL) { + DestroyResourceTree (Mem32Bridge); + gBS->FreePool (Mem32Bridge); + } + + if (PMem32Bridge != NULL) { + DestroyResourceTree (PMem32Bridge); + gBS->FreePool (PMem32Bridge); + } - gBS->FreePool (IoBridge); - gBS->FreePool (Mem32Bridge); - gBS->FreePool (PMem32Bridge); - gBS->FreePool (PMem64Bridge); - gBS->FreePool (Mem64Bridge); + if (PMem64Bridge != NULL) { + DestroyResourceTree (PMem64Bridge); + gBS->FreePool (PMem64Bridge); + } + + if (Mem64Bridge != NULL) { + DestroyResourceTree (Mem64Bridge); + gBS->FreePool (Mem64Bridge); + } return EFI_SUCCESS; } @@ -2015,14 +2053,10 @@ PciHotPlugRequestNotify ( return EFI_INVALID_PARAMETER; } - if (Operation == EfiPciHotPlugRequestAdd) { - if (ChildHandleBuffer == NULL) { - return EFI_INVALID_PARAMETER; - } - } else if ((Operation == EfiPciHotplugRequestRemove) && (*NumberOfChildren != 0)) { - if (ChildHandleBuffer == NULL) { - return EFI_INVALID_PARAMETER; - } + if ((Operation == EfiPciHotPlugRequestAdd) && (ChildHandleBuffer == NULL)) { + return EFI_INVALID_PARAMETER; + } else if ((Operation == EfiPciHotplugRequestRemove) && (*NumberOfChildren != 0) && (ChildHandleBuffer == NULL)) { + return EFI_INVALID_PARAMETER; } Status = gBS->OpenProtocol ( diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c index e85544d08d9e..9b593c4b8b78 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciIo.c @@ -1446,6 +1446,9 @@ SupportPaletteSnoopAttributes ( // if (Temp->Parent == PciIoDevice->Parent) { Status = PCI_READ_COMMAND_REGISTER (Temp, &VGACommand); + if (EFI_ERROR (Status)) { + return EFI_UNSUPPORTED; + } // // If they are on the same bus, either one can diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c index 84fc0161a19c..3ac3e52dc385 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c @@ -381,6 +381,10 @@ DumpResourceMap ( } ChildResources = AllocatePool (sizeof (PCI_RESOURCE_NODE *) * ChildResourceCount); + if (ChildResources == NULL) { + return; + } + ASSERT (ChildResources != NULL); ChildResourceCount = 0; for (Index = 0; Index < ResourceCount; Index++) { @@ -545,6 +549,9 @@ PciHostBridgeResourceAllocator ( PciBarTypeIo16, PciResUsageTypical ); + if (IoBridge == NULL) { + return EFI_OUT_OF_RESOURCES; + } Mem32Bridge = CreateResourceNode ( RootBridgeDev, @@ -554,6 +561,10 @@ PciHostBridgeResourceAllocator ( PciBarTypeMem32, PciResUsageTypical ); + if (Mem32Bridge == NULL) { + FreePool (IoBridge); + return EFI_OUT_OF_RESOURCES; + } PMem32Bridge = CreateResourceNode ( RootBridgeDev, @@ -563,6 +574,11 @@ PciHostBridgeResourceAllocator ( PciBarTypePMem32, PciResUsageTypical ); + if (PMem32Bridge == NULL) { + FreePool (IoBridge); + FreePool (Mem32Bridge); + return EFI_OUT_OF_RESOURCES; + } Mem64Bridge = CreateResourceNode ( RootBridgeDev, @@ -572,6 +588,12 @@ PciHostBridgeResourceAllocator ( PciBarTypeMem64, PciResUsageTypical ); + if (Mem64Bridge == NULL) { + FreePool (IoBridge); + FreePool (Mem32Bridge); + FreePool (PMem32Bridge); + return EFI_OUT_OF_RESOURCES; + } PMem64Bridge = CreateResourceNode ( RootBridgeDev, @@ -581,6 +603,13 @@ PciHostBridgeResourceAllocator ( PciBarTypePMem64, PciResUsageTypical ); + if (PMem64Bridge == NULL) { + FreePool (IoBridge); + FreePool (Mem32Bridge); + FreePool (PMem32Bridge); + FreePool (Mem64Bridge); + return EFI_OUT_OF_RESOURCES; + } // // Get the max ROM size that the root bridge can process @@ -1100,6 +1129,7 @@ PciScanBus ( EFI_HPC_STATE State; UINT64 PciAddress; EFI_HPC_PADDING_ATTRIBUTES Attributes; + VOID *DescriptorsBuffer; EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptors; EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *NextDescriptors; UINT16 BusRange; @@ -1108,16 +1138,17 @@ PciScanBus ( UINT32 TempReservedBusNum; BOOLEAN IsAriEnabled; - PciRootBridgeIo = Bridge->PciRootBridgeIo; - SecondBus = 0; - Register = 0; - State = 0; - Attributes = (EFI_HPC_PADDING_ATTRIBUTES)0; - BusRange = 0; - BusPadding = FALSE; - PciDevice = NULL; - PciAddress = 0; - IsAriEnabled = FALSE; + DescriptorsBuffer = NULL; + PciRootBridgeIo = Bridge->PciRootBridgeIo; + SecondBus = 0; + Register = 0; + State = 0; + Attributes = (EFI_HPC_PADDING_ATTRIBUTES)0; + BusRange = 0; + BusPadding = FALSE; + PciDevice = NULL; + PciAddress = 0; + IsAriEnabled = FALSE; for (Device = 0; Device <= PCI_MAX_DEVICE; Device++) { if (!IsAriEnabled) { @@ -1257,7 +1288,7 @@ PciScanBus ( PciDevice->DevicePath, PciAddress, &State, - (VOID **)&Descriptors, + (VOID **)&DescriptorsBuffer, &Attributes ); @@ -1265,6 +1296,7 @@ PciScanBus ( return Status; } + Descriptors = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)DescriptorsBuffer; BusRange = 0; NextDescriptors = Descriptors; Status = PciGetBusRange ( @@ -1274,7 +1306,9 @@ PciScanBus ( &BusRange ); - FreePool (Descriptors); + FreePool (DescriptorsBuffer); + DescriptorsBuffer = NULL; + Descriptors = NULL; if (!EFI_ERROR (Status)) { BusPadding = TRUE; @@ -1824,7 +1858,7 @@ PciProgramResizableBar ( ); ASSERT_EFI_ERROR (Status); - for (Index = 0; Index < ResizableBarNumber; Index++) { + for (Index = 0; (UINTN)Index < ResizableBarNumber; Index++) { // // When the bit of Capabilities Set, indicates that the Function supports // operating with the BAR sized to (2^Bit) MB. diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c index bd5ace18f6e4..22ad4f0f0147 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciOptionRomSupport.c @@ -717,7 +717,9 @@ ProcessOpRomImage ( EfiOpRomImageNode.EndingOffset = (UINTN)RomBarOffset + ImageSize - 1 - (UINTN)RomBar; PciOptionRomImageDevicePath = AppendDevicePathNode (PciDevice->DevicePath, &EfiOpRomImageNode.Header); - ASSERT (PciOptionRomImageDevicePath != NULL); + if (PciOptionRomImageDevicePath == NULL) { + return EFI_NOT_FOUND; + } // // load image and start image diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c index 8ffd05f327d0..489be7e9ffed 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c @@ -448,13 +448,15 @@ GetResourceFromDevice ( (PciDev->PciBar)[Index].BarType, PciResUsageTypical ); + if (Node != NULL) { + InsertResourceNode ( + Mem32Node, + Node + ); - InsertResourceNode ( - Mem32Node, - Node - ); + ResourceRequested = TRUE; + } - ResourceRequested = TRUE; break; case PciBarTypeMem64: @@ -467,13 +469,15 @@ GetResourceFromDevice ( PciBarTypeMem64, PciResUsageTypical ); + if (Node != NULL) { + InsertResourceNode ( + Mem64Node, + Node + ); - InsertResourceNode ( - Mem64Node, - Node - ); + ResourceRequested = TRUE; + } - ResourceRequested = TRUE; break; case PciBarTypePMem64: @@ -486,13 +490,15 @@ GetResourceFromDevice ( PciBarTypePMem64, PciResUsageTypical ); + if (Node != NULL) { + InsertResourceNode ( + PMem64Node, + Node + ); - InsertResourceNode ( - PMem64Node, - Node - ); + ResourceRequested = TRUE; + } - ResourceRequested = TRUE; break; case PciBarTypePMem32: @@ -505,12 +511,14 @@ GetResourceFromDevice ( PciBarTypePMem32, PciResUsageTypical ); + if (Node != NULL) { + InsertResourceNode ( + PMem32Node, + Node + ); + ResourceRequested = TRUE; + } - InsertResourceNode ( - PMem32Node, - Node - ); - ResourceRequested = TRUE; break; case PciBarTypeIo16: @@ -524,12 +532,14 @@ GetResourceFromDevice ( PciBarTypeIo16, PciResUsageTypical ); + if (Node != NULL) { + InsertResourceNode ( + IoNode, + Node + ); + ResourceRequested = TRUE; + } - InsertResourceNode ( - IoNode, - Node - ); - ResourceRequested = TRUE; break; case PciBarTypeUnknown: @@ -555,11 +565,12 @@ GetResourceFromDevice ( PciBarTypeMem32, PciResUsageTypical ); - - InsertResourceNode ( - Mem32Node, - Node - ); + if (Node != NULL) { + InsertResourceNode ( + Mem32Node, + Node + ); + } break; @@ -573,11 +584,12 @@ GetResourceFromDevice ( PciBarTypeMem64, PciResUsageTypical ); - - InsertResourceNode ( - Mem64Node, - Node - ); + if (Node != NULL) { + InsertResourceNode ( + Mem64Node, + Node + ); + } break; @@ -591,11 +603,12 @@ GetResourceFromDevice ( PciBarTypePMem64, PciResUsageTypical ); - - InsertResourceNode ( - PMem64Node, - Node - ); + if (Node != NULL) { + InsertResourceNode ( + PMem64Node, + Node + ); + } break; @@ -609,11 +622,13 @@ GetResourceFromDevice ( PciBarTypePMem32, PciResUsageTypical ); + if (Node != NULL) { + InsertResourceNode ( + PMem32Node, + Node + ); + } - InsertResourceNode ( - PMem32Node, - Node - ); break; case PciBarTypeIo16: @@ -820,6 +835,32 @@ CreateResourceMap ( PciResUsageTypical ); + if ((IoBridge == NULL) || (Mem32Bridge == NULL) || (PMem32Bridge == NULL) || + (Mem64Bridge == NULL) || (PMem64Bridge == NULL)) + { + if (IoBridge != NULL) { + FreePool (IoBridge); + } + + if (Mem32Bridge != NULL) { + FreePool (Mem32Bridge); + } + + if (PMem32Bridge != NULL) { + FreePool (PMem32Bridge); + } + + if (Mem64Bridge != NULL) { + FreePool (Mem64Bridge); + } + + if (PMem64Bridge != NULL) { + FreePool (PMem64Bridge); + } + + return; + } + // // Recursively create resource map on this bridge // @@ -1813,11 +1854,13 @@ ResourcePaddingForCardBusBridge ( PciBarTypeMem32, PciResUsagePadding ); - - InsertResourceNode ( - Mem32Node, - Node - ); + ASSERT (Node != NULL); + if (Node != NULL) { + InsertResourceNode ( + Mem32Node, + Node + ); + } // // Memory Base/Limit Register 1 @@ -1832,10 +1875,13 @@ ResourcePaddingForCardBusBridge ( PciResUsagePadding ); - InsertResourceNode ( - PMem32Node, - Node - ); + ASSERT (Node != NULL); + if (Node != NULL) { + InsertResourceNode ( + PMem32Node, + Node + ); + } // // Io Base/Limit @@ -1850,10 +1896,13 @@ ResourcePaddingForCardBusBridge ( PciResUsagePadding ); - InsertResourceNode ( - IoNode, - Node - ); + ASSERT (Node != NULL); + if (Node != NULL) { + InsertResourceNode ( + IoNode, + Node + ); + } // // Io Base/Limit @@ -1868,10 +1917,13 @@ ResourcePaddingForCardBusBridge ( PciResUsagePadding ); - InsertResourceNode ( - IoNode, - Node - ); + ASSERT (Node != NULL); + if (Node != NULL) { + InsertResourceNode ( + IoNode, + Node + ); + } } /** @@ -2142,10 +2194,13 @@ ApplyResourcePadding ( PciBarTypeIo16, PciResUsagePadding ); - InsertResourceNode ( - IoNode, - Node - ); + + if (Node != NULL) { + InsertResourceNode ( + IoNode, + Node + ); + } } Ptr++; @@ -2167,10 +2222,12 @@ ApplyResourcePadding ( PciBarTypePMem32, PciResUsagePadding ); - InsertResourceNode ( - PMem32Node, - Node - ); + if (Node != NULL) { + InsertResourceNode ( + PMem32Node, + Node + ); + } } Ptr++; @@ -2190,10 +2247,12 @@ ApplyResourcePadding ( PciBarTypeMem32, PciResUsagePadding ); - InsertResourceNode ( - Mem32Node, - Node - ); + if (Node != NULL) { + InsertResourceNode ( + Mem32Node, + Node + ); + } } Ptr++; @@ -2215,10 +2274,12 @@ ApplyResourcePadding ( PciBarTypePMem64, PciResUsagePadding ); - InsertResourceNode ( - PMem64Node, - Node - ); + if (Node != NULL) { + InsertResourceNode ( + PMem64Node, + Node + ); + } } Ptr++; @@ -2238,10 +2299,12 @@ ApplyResourcePadding ( PciBarTypeMem64, PciResUsagePadding ); - InsertResourceNode ( - Mem64Node, - Node - ); + if (Node != NULL) { + InsertResourceNode ( + Mem64Node, + Node + ); + } } Ptr++; diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c index d573e532bac8..c4c4059c4b9a 100644 --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridge.c @@ -668,6 +668,9 @@ ResourceConflict ( sizeof (EFI_ACPI_END_TAG_DESCRIPTOR) ); ASSERT (Resources != NULL); + if (Resources == NULL) { + return; + } for (Link = GetFirstNode (&HostBridge->RootBridges), Descriptor = Resources ; !IsNull (&HostBridge->RootBridges, Link) diff --git a/MdeModulePkg/Bus/Pci/PciSioSerialDxe/Serial.c b/MdeModulePkg/Bus/Pci/PciSioSerialDxe/Serial.c index 8b1ce70118c0..15b5f65b5ecc 100644 --- a/MdeModulePkg/Bus/Pci/PciSioSerialDxe/Serial.c +++ b/MdeModulePkg/Bus/Pci/PciSioSerialDxe/Serial.c @@ -891,8 +891,7 @@ SerialControllerDriverStart ( ControllerNumber = 0; ContainsControllerNode = FALSE; SerialDevices = GetChildSerialDevices (Controller, IoProtocolGuid, &SerialDeviceCount); - - if (SerialDeviceCount != 0) { + if ((SerialDevices != NULL) && (SerialDeviceCount != 0)) { if (RemainingDevicePath == NULL) { // // If the SerialIo instance is already created, NULL as RemainingDevicePath is treated @@ -1016,7 +1015,12 @@ SerialControllerDriverStart ( // Restore the PCI attributes when all children is destroyed (PciDeviceInfo->ChildCount == 0). // PciDeviceInfo = AllocatePool (sizeof (PCI_DEVICE_INFO)); - ASSERT (PciDeviceInfo != NULL); + + if (PciDeviceInfo == NULL) { + ASSERT (PciDeviceInfo != NULL); + return EFI_OUT_OF_RESOURCES; + } + PciDeviceInfo->ChildCount = 0; PciDeviceInfo->PciIo = ParentIo.PciIo; Status = ParentIo.PciIo->Attributes ( diff --git a/MdeModulePkg/Bus/Pci/PciSioSerialDxe/SerialIo.c b/MdeModulePkg/Bus/Pci/PciSioSerialDxe/SerialIo.c index 8a85a6c3b886..7b056a3ba828 100644 --- a/MdeModulePkg/Bus/Pci/PciSioSerialDxe/SerialIo.c +++ b/MdeModulePkg/Bus/Pci/PciSioSerialDxe/SerialIo.c @@ -1234,7 +1234,7 @@ SerialRead ( ) { SERIAL_DEV *SerialDevice; - UINT32 Index; + UINTN Index; UINT8 *CharBuffer; UINTN Elapsed; EFI_STATUS Status; diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c index 8496ce472768..0b79dbb226e5 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.c @@ -545,6 +545,7 @@ SdMmcPciHcDriverBindingStart ( EFI_PCI_IO_PROTOCOL *PciIo; UINT64 Supports; UINT64 PciAttributes; + UINT8 SlotMax; UINT8 SlotNum; UINT8 FirstBar; UINT8 Slot; @@ -647,7 +648,14 @@ SdMmcPciHcDriverBindingStart ( } Support64BitDma = TRUE; - for (Slot = FirstBar; Slot < (FirstBar + SlotNum); Slot++) { + + Status = SafeUint8Add (FirstBar, SlotNum, &SlotMax); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "[%a] Overflow when calculating SlotMax!\n", __func__)); + goto Done; + } + + for (Slot = FirstBar; Slot < SlotMax; Slot++) { Private->Slot[Slot].Enable = TRUE; // // Get SD/MMC Pci Host Controller Version diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h index b76c7cffa279..aa8040304288 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.h @@ -25,6 +25,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf index e502443ddd5b..4e5c11299377 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHcDxe.inf @@ -57,6 +57,7 @@ UefiDriverEntryPoint DebugLib PcdLib + SafeIntLib [Protocols] gEdkiiSdMmcOverrideProtocolGuid ## SOMETIMES_CONSUMES diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c index 2e7497a89db1..e127d047c242 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c @@ -1472,7 +1472,7 @@ BuildAdmaDescTable ( EFI_PHYSICAL_ADDRESS Data; UINT64 DataLen; UINT64 Entries; - UINT32 Index; + UINT64 Index; UINT64 Remaining; UINT64 Address; UINTN TableSize; diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.c index 89e0a1b6a416..58cd75ec8989 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.c +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.c @@ -84,6 +84,7 @@ InitializeSdMmcHcPeim ( UINT8 SubClass; UINT8 BaseClass; UINT8 SlotInfo; + UINT8 SlotMax; UINT8 SlotNum; UINT8 FirstBar; UINT8 Index; @@ -133,7 +134,13 @@ InitializeSdMmcHcPeim ( SlotNum = (*(SD_MMC_HC_PEI_SLOT_INFO *)&SlotInfo).SlotNum + 1; ASSERT ((FirstBar + SlotNum) < MAX_SD_MMC_SLOTS); - for (Index = 0, Slot = FirstBar; Slot < (FirstBar + SlotNum); Index++, Slot++) { + Status = SafeUint8Add (FirstBar, SlotNum, &SlotMax); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "[%a] Overflow when calculating SlotMax!\n", __func__)); + return Status; + } + + for (Index = 0, Slot = FirstBar; Slot < SlotMax; Index++, Slot++) { // // Get the SD/MMC Pci host controller's MMIO region size. // diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.h b/MdeModulePkg/Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.h index ade59dd6e354..ae0077dbfb20 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.h +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.h @@ -21,6 +21,7 @@ #include #include #include +#include #define SD_MMC_HC_PEI_SIGNATURE SIGNATURE_32 ('S', 'D', 'M', 'C') diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.inf b/MdeModulePkg/Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.inf index 6879055300e5..a1fdd0f50c35 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.inf +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcPei/SdMmcPciHcPei.inf @@ -37,6 +37,7 @@ PeiServicesLib MemoryAllocationLib PeimEntryPoint + SafeIntLib [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdSdMmcPciHostControllerMmioBase ## CONSUMES diff --git a/MdeModulePkg/Bus/Pci/UhciPei/UhcPeim.c b/MdeModulePkg/Bus/Pci/UhciPei/UhcPeim.c index 96abf3ab13bd..d2359db7162f 100644 --- a/MdeModulePkg/Bus/Pci/UhciPei/UhcPeim.c +++ b/MdeModulePkg/Bus/Pci/UhciPei/UhcPeim.c @@ -272,7 +272,8 @@ UhcControlTransfer ( StatusReg = UhcDev->UsbHostControllerBaseAddress + USBSTS; - PktID = INPUT_PACKET_ID; + PktID = INPUT_PACKET_ID; + DataMap = NULL; RequestMap = NULL; @@ -546,6 +547,7 @@ UhcBulkTransfer ( PtrTD = NULL; PtrFirstTD = NULL; PtrPreTD = NULL; + DataMap = NULL; DataLen = 0; ShortPacketEnable = FALSE; @@ -2848,6 +2850,8 @@ InitializeMemoryManagement ( EFI_STATUS Status; UINTN MemPages; + MemoryHeader = NULL; + MemPages = NORMAL_MEMORY_BLOCK_UNIT_IN_PAGES; Status = CreateMemoryBlock (UhcDev, &MemoryHeader, MemPages); if (EFI_ERROR (Status)) { @@ -2886,6 +2890,8 @@ UhcAllocatePool ( *Pool = NULL; + NewMemoryHeader = NULL; + MemoryHeader = UhcDev->Header1; // diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c index 3caa060f3564..4138c1656668 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c @@ -513,7 +513,12 @@ XhcInitSched ( Entries = (Xhc->MaxSlotsEn + 1) * sizeof (UINT64); Dcbaa = UsbHcAllocateMem (Xhc->MemPool, Entries, FALSE); ASSERT (Dcbaa != NULL); - ZeroMem (Dcbaa, Entries); + + if (Dcbaa != NULL) { + ZeroMem (Dcbaa, Entries); + } else { + return; + } // // A Scratchpad Buffer is a PAGESIZE block of system memory located on a PAGESIZE boundary. @@ -803,6 +808,11 @@ CreateEventRing ( Buf = UsbHcAllocateMem (Xhc->MemPool, Size, TRUE); ASSERT (Buf != NULL); ASSERT (((UINTN)Buf & 0x3F) == 0); + + if (Buf == NULL) { + return; + } + ZeroMem (Buf, Size); EventRing->EventRingSeg0 = Buf; @@ -822,6 +832,11 @@ CreateEventRing ( Buf = UsbHcAllocateMem (Xhc->MemPool, Size, FALSE); ASSERT (Buf != NULL); ASSERT (((UINTN)Buf & 0x3F) == 0); + + if (Buf == NULL) { + return; + } + ZeroMem (Buf, Size); ERSTBase = (EVENT_RING_SEG_TABLE_ENTRY *)Buf; @@ -900,6 +915,11 @@ CreateTransferRing ( Buf = UsbHcAllocateMem (Xhc->MemPool, sizeof (TRB_TEMPLATE) * TrbNum, TRUE); ASSERT (Buf != NULL); ASSERT (((UINTN)Buf & 0x3F) == 0); + + if (Buf == NULL) { + return; + } + ZeroMem (Buf, sizeof (TRB_TEMPLATE) * TrbNum); TransferRing->RingSeg0 = Buf; @@ -2199,6 +2219,11 @@ XhcInitializeDeviceSlot ( InputContext = UsbHcAllocateMem (Xhc->MemPool, sizeof (INPUT_CONTEXT), FALSE); ASSERT (InputContext != NULL); ASSERT (((UINTN)InputContext & 0x3F) == 0); + + if (InputContext == NULL) { + return RETURN_OUT_OF_RESOURCES; + } + ZeroMem (InputContext, sizeof (INPUT_CONTEXT)); Xhc->UsbDevContext[SlotId].InputContext = (VOID *)InputContext; @@ -2302,6 +2327,11 @@ XhcInitializeDeviceSlot ( OutputContext = UsbHcAllocateMem (Xhc->MemPool, sizeof (DEVICE_CONTEXT), FALSE); ASSERT (OutputContext != NULL); ASSERT (((UINTN)OutputContext & 0x3F) == 0); + + if (OutputContext == NULL) { + return EFI_OUT_OF_RESOURCES; + } + ZeroMem (OutputContext, sizeof (DEVICE_CONTEXT)); Xhc->UsbDevContext[SlotId].OutputContext = OutputContext; @@ -2425,6 +2455,11 @@ XhcInitializeDeviceSlot64 ( InputContext = UsbHcAllocateMem (Xhc->MemPool, sizeof (INPUT_CONTEXT_64), FALSE); ASSERT (InputContext != NULL); ASSERT (((UINTN)InputContext & 0x3F) == 0); + + if (InputContext == NULL) { + return EFI_OUT_OF_RESOURCES; + } + ZeroMem (InputContext, sizeof (INPUT_CONTEXT_64)); Xhc->UsbDevContext[SlotId].InputContext = (VOID *)InputContext; @@ -2528,6 +2563,11 @@ XhcInitializeDeviceSlot64 ( OutputContext = UsbHcAllocateMem (Xhc->MemPool, sizeof (DEVICE_CONTEXT_64), FALSE); ASSERT (OutputContext != NULL); ASSERT (((UINTN)OutputContext & 0x3F) == 0); + + if (OutputContext == NULL) { + return EFI_OUT_OF_RESOURCES; + } + ZeroMem (OutputContext, sizeof (DEVICE_CONTEXT_64)); Xhc->UsbDevContext[SlotId].OutputContext = OutputContext; diff --git a/MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c b/MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c index 88db5fe46eae..2aff2f34316c 100644 --- a/MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c +++ b/MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.c @@ -32,6 +32,8 @@ UsbHcAllocMemBlock ( UINTN PageNumber; EFI_PHYSICAL_ADDRESS TempPtr; + Mapping = NULL; + PageNumber = EFI_SIZE_TO_PAGES (sizeof (USBHC_MEM_BLOCK)); Status = PeiServicesAllocatePages ( EfiBootServicesData, diff --git a/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c b/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c index e79110c14e11..fd3169254b02 100644 --- a/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c +++ b/MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.c @@ -2535,8 +2535,8 @@ ScsiDiskInquiryDevice ( EFI_SCSI_SENSE_DATA *SenseDataArray; UINTN NumberOfSenseKeys; EFI_STATUS Status; - UINT8 MaxRetry; - UINT8 Index; + UINT32 MaxRetry; + UINT32 Index; EFI_SCSI_SUPPORTED_VPD_PAGES_VPD_PAGE *SupportedVpdPages; EFI_SCSI_BLOCK_LIMITS_VPD_PAGE *BlockLimits; UINTN PageLength; @@ -2619,7 +2619,7 @@ ScsiDiskInquiryDevice ( // // Locate the code for the Block Limits VPD page // - for (Index = 0; Index < PageLength; Index++) { + for (Index = 0; (UINTN)Index < PageLength; Index++) { // // Sanity check // diff --git a/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHcMem.c b/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHcMem.c index 6778254b6174..8ff0f621a4b9 100644 --- a/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHcMem.c +++ b/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHcMem.c @@ -30,6 +30,7 @@ EmmcPeimAllocMemBlock ( TempPtr = NULL; Block = NULL; + Mapping = NULL; Status = PeiServicesAllocatePool (sizeof (EMMC_PEIM_MEM_BLOCK), &TempPtr); if (EFI_ERROR (Status)) { diff --git a/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c b/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c index bafd71e9b5cc..89df43c9ddd8 100644 --- a/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c +++ b/MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c @@ -934,7 +934,7 @@ BuildAdmaDescTable ( EFI_PHYSICAL_ADDRESS Data; UINT64 DataLen; UINT64 Entries; - UINT32 Index; + UINT64 Index; UINT64 Remaining; UINT32 Address; diff --git a/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHcMem.c b/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHcMem.c index 27aec1fbf397..ed1b68915749 100644 --- a/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHcMem.c +++ b/MdeModulePkg/Bus/Sd/SdBlockIoPei/SdHcMem.c @@ -30,6 +30,7 @@ SdPeimAllocMemBlock ( TempPtr = NULL; Block = NULL; + Mapping = NULL; Status = PeiServicesAllocatePool (sizeof (SD_PEIM_MEM_BLOCK), &TempPtr); if (EFI_ERROR (Status)) { diff --git a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHcMem.c b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHcMem.c index 562a77676c36..49c4d8947029 100644 --- a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHcMem.c +++ b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHcMem.c @@ -31,6 +31,7 @@ UfsPeimAllocMemBlock ( TempPtr = NULL; Block = NULL; + Mapping = NULL; Status = PeiServicesAllocatePool (sizeof (UFS_PEIM_MEM_BLOCK), &TempPtr); if (EFI_ERROR (Status)) { diff --git a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c index 360b642611b9..f8acc71828b2 100644 --- a/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c +++ b/MdeModulePkg/Bus/Ufs/UfsBlockIoPei/UfsHci.c @@ -317,7 +317,7 @@ UfsInitUtpPrdt ( IN UINT32 BufferSize ) { - UINT32 PrdtIndex; + UINTN PrdtIndex; UINT32 RemainingLen; UINT8 *Remaining; UINTN PrdtNumber; diff --git a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c index 4a9fa01e7d81..46f837ecbb21 100644 --- a/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c +++ b/MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThruHci.c @@ -405,7 +405,7 @@ UfsInitUtpPrdt ( Remaining = Buffer; PrdtNumber = (UINTN)DivU64x32 ((UINT64)BufferSize + UFS_MAX_DATA_LEN_PER_PRD - 1, UFS_MAX_DATA_LEN_PER_PRD); - for (PrdtIndex = 0; PrdtIndex < PrdtNumber; PrdtIndex++) { + for (PrdtIndex = 0; (UINTN)PrdtIndex < PrdtNumber; PrdtIndex++) { if (RemainingLen < UFS_MAX_DATA_LEN_PER_PRD) { Prdt[PrdtIndex].DbCount = (UINT32)RemainingLen - 1; } else { diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c index 2826ac130ef7..bed8ed5a45ab 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbBus.c @@ -739,7 +739,7 @@ UsbIoGetStringDescriptor ( EFI_USB_STRING_DESCRIPTOR *StrDesc; EFI_TPL OldTpl; UINT8 *Buf; - UINT8 Index; + UINT16 Index; EFI_STATUS Status; if ((StringIndex == 0) || (LangID == 0)) { diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c index 740e7babb0ca..bc92841798e0 100644 --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbUtility.c @@ -957,6 +957,7 @@ UsbBusAddWantedUsbIoDP ( EFI_STATUS Status; EFI_DEVICE_PATH_PROTOCOL *DevicePathPtr; + DevicePathPtr = NULL; // // Check whether remaining device path is valid // @@ -1001,9 +1002,13 @@ UsbBusAddWantedUsbIoDP ( } ASSERT (DevicePathPtr != NULL); - Status = AddUsbDPToList (DevicePathPtr, &Bus->WantedUsbIoDPList); - ASSERT (!EFI_ERROR (Status)); - FreePool (DevicePathPtr); + + if (DevicePathPtr != NULL) { + Status = AddUsbDPToList (DevicePathPtr, &Bus->WantedUsbIoDPList); + ASSERT (!EFI_ERROR (Status)); + FreePool (DevicePathPtr); + } + return EFI_SUCCESS; } @@ -1060,7 +1065,10 @@ UsbBusIsWantedUsbIO ( // Create new Usb device path according to the usb part in UsbIo full device path // DevicePathPtr = GetUsbDPFromFullDP (UsbIf->DevicePath); - ASSERT (DevicePathPtr != NULL); + + if (DevicePathPtr == NULL) { + return FALSE; + } DoConvert = FALSE; WantedListIndex = WantedUsbIoDPListPtr->ForwardLink; diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c index b5a6459a35d2..1aa8ff77d49a 100644 --- a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c +++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c @@ -438,15 +438,17 @@ GetCurrentKeyboardLayout ( KeyboardLayout = AllocatePool (Length); ASSERT (KeyboardLayout != NULL); - Status = HiiDatabase->GetKeyboardLayout ( - HiiDatabase, - NULL, - &Length, - KeyboardLayout - ); - if (EFI_ERROR (Status)) { - FreePool (KeyboardLayout); - KeyboardLayout = NULL; + if (KeyboardLayout != NULL) { + Status = HiiDatabase->GetKeyboardLayout ( + HiiDatabase, + NULL, + &Length, + KeyboardLayout + ); + if (EFI_ERROR (Status)) { + FreePool (KeyboardLayout); + KeyboardLayout = NULL; + } } } @@ -683,7 +685,10 @@ SetKeyboardLayoutEvent ( // TableEntry = GetKeyDescriptor (UsbKeyboardDevice, 0x58); KeyDescriptor = GetKeyDescriptor (UsbKeyboardDevice, 0x28); - CopyMem (TableEntry, KeyDescriptor, sizeof (EFI_KEY_DESCRIPTOR)); + + if ((TableEntry != NULL) && (KeyDescriptor != NULL)) { + CopyMem (TableEntry, KeyDescriptor, sizeof (EFI_KEY_DESCRIPTOR)); + } FreePool (KeyboardLayout); } diff --git a/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c b/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c index ad5f066ec9ba..cd3c7d104361 100644 --- a/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c +++ b/MdeModulePkg/Bus/Usb/UsbMouseAbsolutePointerDxe/UsbMouseAbsolutePointer.c @@ -160,7 +160,12 @@ USBMouseAbsolutePointerDriverBindingStart ( } UsbMouseAbsolutePointerDevice = AllocateZeroPool (sizeof (USB_MOUSE_ABSOLUTE_POINTER_DEV)); - ASSERT (UsbMouseAbsolutePointerDevice != NULL); + + if (UsbMouseAbsolutePointerDevice == NULL) { + ASSERT (UsbMouseAbsolutePointerDevice != NULL); + Status = EFI_OUT_OF_RESOURCES; + goto ErrorExit; + } UsbMouseAbsolutePointerDevice->UsbIo = UsbIo; UsbMouseAbsolutePointerDevice->Signature = USB_MOUSE_ABSOLUTE_POINTER_DEV_SIGNATURE; @@ -631,7 +636,12 @@ InitializeUsbMouseDevice ( } ReportDesc = AllocateZeroPool (MouseHidDesc->HidClassDesc[0].DescriptorLength); - ASSERT (ReportDesc != NULL); + + if (ReportDesc == NULL) { + ASSERT (ReportDesc != NULL); + FreePool (Buf); + return EFI_OUT_OF_RESOURCES; + } Status = UsbGetReportDescriptor ( UsbIo, diff --git a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c index cf9d55687766..cc5f8836d778 100644 --- a/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c @@ -773,7 +773,10 @@ FvIsBeingProcessed ( } KnownHandle = AllocateZeroPool (sizeof (KNOWN_HANDLE)); - ASSERT (KnownHandle != NULL); + if (KnownHandle == NULL) { + ASSERT (KnownHandle != NULL); + return NULL; + } KnownHandle->Signature = KNOWN_HANDLE_SIGNATURE; KnownHandle->Handle = FvHandle; @@ -850,6 +853,7 @@ CoreFvToDevicePath ( @retval EFI_ALREADY_STARTED The driver has already been started. Only one DriverName may be active in the system at any one time. + @retval EFI_OUT_OF_RESOURCES If memory could not be allocated for the DriverEntry. **/ EFI_STATUS @@ -867,7 +871,11 @@ CoreAddToDriverList ( // NULL or FALSE. // DriverEntry = AllocateZeroPool (sizeof (EFI_CORE_DRIVER_ENTRY)); - ASSERT (DriverEntry != NULL); + if (DriverEntry == NULL) { + ASSERT (DriverEntry != NULL); + return EFI_OUT_OF_RESOURCES; + } + if (Type == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) { DriverEntry->IsFvImage = TRUE; } @@ -1050,13 +1058,15 @@ CoreProcessFvImageFile ( // if (gSecurity != NULL) { FvFileDevicePath = CoreFvToDevicePath (Fv, FvHandle, FileName); - Status = gSecurity->FileAuthenticationState ( - gSecurity, - AuthenticationStatus, - FvFileDevicePath - ); if (FvFileDevicePath != NULL) { + Status = gSecurity->FileAuthenticationState ( + gSecurity, + AuthenticationStatus, + FvFileDevicePath + ); FreePool (FvFileDevicePath); + } else { + Status = EFI_OUT_OF_RESOURCES; } if (Status != EFI_SUCCESS) { diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index 6ea89fbc8b3e..e240bd1cc114 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -152,7 +152,10 @@ CoreDumpGcdMemorySpaceMap ( UINTN Index; Status = CoreGetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap); - ASSERT (Status == EFI_SUCCESS && MemorySpaceMap != NULL); + if (!((Status == EFI_SUCCESS) && (MemorySpaceMap != NULL))) { + ASSERT ((Status == EFI_SUCCESS) && (MemorySpaceMap != NULL)); + return; + } if (InitialMap) { DEBUG ((DEBUG_GCD, "GCD:Initial GCD Memory Space Map\n")); @@ -198,7 +201,10 @@ CoreDumpGcdIoSpaceMap ( UINTN Index; Status = CoreGetIoSpaceMap (&NumberOfDescriptors, &IoSpaceMap); - ASSERT (Status == EFI_SUCCESS && IoSpaceMap != NULL); + if (!((Status == EFI_SUCCESS) && (IoSpaceMap != NULL))) { + ASSERT ((Status == EFI_SUCCESS) && (IoSpaceMap != NULL)); + return; + } if (InitialMap) { DEBUG ((DEBUG_GCD, "GCD:Initial GCD I/O Space Map\n")); @@ -760,7 +766,7 @@ CoreConvertSpace ( // Search for the list of descriptors that cover the range BaseAddress to BaseAddress+Length // Status = CoreSearchGcdMapEntry (BaseAddress, Length, &StartLink, &EndLink, Map); - if (EFI_ERROR (Status)) { + if (EFI_ERROR (Status) || ((StartLink == NULL) || (EndLink == NULL))) { Status = EFI_UNSUPPORTED; goto Done; @@ -879,7 +885,7 @@ CoreConvertSpace ( // Allocate work space to perform this operation // Status = CoreAllocateGcdMapEntry (&TopEntry, &BottomEntry); - if (EFI_ERROR (Status)) { + if (EFI_ERROR (Status) || ((TopEntry == NULL) || (BottomEntry == NULL))) { Status = EFI_OUT_OF_RESOURCES; goto Done; } @@ -1191,7 +1197,7 @@ CoreAllocateSpace ( // Search for the list of descriptors that cover the range BaseAddress to BaseAddress+Length // Status = CoreSearchGcdMapEntry (*BaseAddress, Length, &StartLink, &EndLink, Map); - if (EFI_ERROR (Status)) { + if (EFI_ERROR (Status) || ((StartLink == NULL) || (EndLink == NULL))) { Status = EFI_NOT_FOUND; goto Done; } @@ -1284,7 +1290,7 @@ CoreAllocateSpace ( // Search for the list of descriptors that cover the range BaseAddress to BaseAddress+Length // Status = CoreSearchGcdMapEntry (*BaseAddress, Length, &StartLink, &EndLink, Map); - if (EFI_ERROR (Status)) { + if (EFI_ERROR (Status) || ((StartLink == NULL) || (EndLink == NULL))) { Status = EFI_NOT_FOUND; goto Done; } @@ -1324,7 +1330,7 @@ CoreAllocateSpace ( // Allocate work space to perform this operation // Status = CoreAllocateGcdMapEntry (&TopEntry, &BottomEntry); - if (EFI_ERROR (Status)) { + if (EFI_ERROR (Status) || ((TopEntry == NULL) || (BottomEntry == NULL))) { Status = EFI_OUT_OF_RESOURCES; goto Done; } @@ -1637,7 +1643,7 @@ CoreGetMemorySpaceDescriptor ( // Search for the list of descriptors that contain BaseAddress // Status = CoreSearchGcdMapEntry (BaseAddress, 1, &StartLink, &EndLink, &mGcdMemorySpaceMap); - if (EFI_ERROR (Status)) { + if (EFI_ERROR (Status) || ((StartLink == NULL) || (EndLink == NULL))) { Status = EFI_NOT_FOUND; } else { ASSERT (StartLink != NULL && EndLink != NULL); @@ -2015,7 +2021,7 @@ CoreGetIoSpaceDescriptor ( // Search for the list of descriptors that contain BaseAddress // Status = CoreSearchGcdMapEntry (BaseAddress, 1, &StartLink, &EndLink, &mGcdIoSpaceMap); - if (EFI_ERROR (Status)) { + if (EFI_ERROR (Status) || ((StartLink == NULL) || (EndLink == NULL))) { Status = EFI_NOT_FOUND; } else { ASSERT (StartLink != NULL && EndLink != NULL); @@ -2608,7 +2614,11 @@ CoreInitializeGcdServices ( // Get the number of address lines in the I/O and Memory space for the CPU // CpuHob = GetFirstHob (EFI_HOB_TYPE_CPU); - ASSERT (CpuHob != NULL); + if (CpuHob == NULL) { + ASSERT (CpuHob != NULL); + return EFI_OUT_OF_RESOURCES; + } + SizeOfMemorySpace = CpuHob->SizeOfMemorySpace; SizeOfIoSpace = CpuHob->SizeOfIoSpace; @@ -2616,7 +2626,10 @@ CoreInitializeGcdServices ( // Initialize the GCD Memory Space Map // Entry = AllocateCopyPool (sizeof (EFI_GCD_MAP_ENTRY), &mGcdMemorySpaceMapEntryTemplate); - ASSERT (Entry != NULL); + if (Entry == NULL) { + ASSERT (Entry != NULL); + return EFI_OUT_OF_RESOURCES; + } Entry->EndAddress = LShiftU64 (1, SizeOfMemorySpace) - 1; @@ -2628,7 +2641,10 @@ CoreInitializeGcdServices ( // Initialize the GCD I/O Space Map // Entry = AllocateCopyPool (sizeof (EFI_GCD_MAP_ENTRY), &mGcdIoSpaceMapEntryTemplate); - ASSERT (Entry != NULL); + if (Entry == NULL) { + ASSERT (Entry != NULL); + return EFI_OUT_OF_RESOURCES; + } Entry->EndAddress = LShiftU64 (1, SizeOfIoSpace) - 1; @@ -2848,7 +2864,10 @@ CoreInitializeGcdServices ( (UINTN)PhitHob->EfiFreeMemoryBottom - (UINTN)(*HobStart), *HobStart ); - ASSERT (NewHobList != NULL); + if (NewHobList == NULL) { + ASSERT (NewHobList != NULL); + return EFI_OUT_OF_RESOURCES; + } *HobStart = NewHobList; gHobList = NewHobList; diff --git a/MdeModulePkg/Core/Dxe/Hand/Handle.c b/MdeModulePkg/Core/Dxe/Hand/Handle.c index b5ff3fdcd1d4..2f19fffb317a 100644 --- a/MdeModulePkg/Core/Dxe/Hand/Handle.c +++ b/MdeModulePkg/Core/Dxe/Hand/Handle.c @@ -1107,6 +1107,7 @@ CoreOpenProtocol ( return EFI_INVALID_PARAMETER; } + Prot = NULL; // // Lock the protocol database // @@ -1285,7 +1286,7 @@ CoreOpenProtocol ( // Keep Interface unmodified in case of any Error // except EFI_ALREADY_STARTED and EFI_UNSUPPORTED. // - if (!EFI_ERROR (Status) || (Status == EFI_ALREADY_STARTED)) { + if ((!EFI_ERROR (Status) || (Status == EFI_ALREADY_STARTED)) && (Prot != NULL)) { // // According to above logic, if 'Prot' is NULL, then the 'Status' must be // EFI_UNSUPPORTED. Here the 'Status' is not EFI_UNSUPPORTED, so 'Prot' diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Image/Image.c index 8d12f93d7f95..830e25e967c8 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -162,7 +162,10 @@ PeCoffEmuProtocolNotify ( } Entry = AllocateZeroPool (sizeof (*Entry)); - ASSERT (Entry != NULL); + if (Entry == NULL) { + ASSERT (Entry != NULL); + break; + } Entry->Emulator = Emulator; Entry->MachineType = Entry->Emulator->MachineType; @@ -1260,6 +1263,11 @@ CoreLoadImageCommon ( // LoadFile () may cause the device path of the Handle be updated. // OriginalFilePath = AppendDevicePath (DevicePathFromHandle (DeviceHandle), Node); + if (OriginalFilePath == NULL) { + Image = NULL; + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } } } } diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index e4daa741b971..89ac68a4b595 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -339,7 +339,12 @@ CoreFreeMemoryMapStack ( // Entry = AllocateMemoryMapEntry (); - ASSERT (Entry); + // If entry allocation failed once, it is unlikely to succeed moving forward + // However, we can try since we're in the middle of moving list nodes + if (Entry == NULL) { + ASSERT (Entry != NULL); + continue; + } // // Update to proper entry diff --git a/MdeModulePkg/Core/Dxe/Mem/Pool.c b/MdeModulePkg/Core/Dxe/Mem/Pool.c index 72293e6dfe40..f0f8ee247131 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Pool.c +++ b/MdeModulePkg/Core/Dxe/Mem/Pool.c @@ -427,6 +427,10 @@ CoreAllocatePoolI ( NoPages = EFI_SIZE_TO_PAGES (Size) + EFI_SIZE_TO_PAGES (Granularity) - 1; NoPages &= ~(UINTN)(EFI_SIZE_TO_PAGES (Granularity) - 1); Head = CoreAllocatePoolPagesI (PoolType, NoPages, Granularity, NeedGuard); + if (Head == NULL) { + return NULL; + } + if (NeedGuard) { Head = AdjustPoolHeadA ((EFI_PHYSICAL_ADDRESS)(UINTN)Head, NoPages, Size); } diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c index a11c455ab598..d101927e4df7 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryAttributesTable.c @@ -149,7 +149,10 @@ InstallMemoryAttributesTable ( do { MemoryMap = AllocatePool (MemoryMapSize); - ASSERT (MemoryMap != NULL); + if (MemoryMap == NULL) { + ASSERT (MemoryMap != NULL); + return; + } Status = CoreGetMemoryMapWithSeparatedImageSection ( &MemoryMapSize, @@ -180,7 +183,12 @@ InstallMemoryAttributesTable ( // Allocate MemoryAttributesTable // MemoryAttributesTable = AllocatePool (sizeof (EFI_MEMORY_ATTRIBUTES_TABLE) + DescriptorSize * RuntimeEntryCount); - ASSERT (MemoryAttributesTable != NULL); + if (MemoryAttributesTable == NULL) { + ASSERT (MemoryAttributesTable != NULL); + FreePool (MemoryMapStart); + return; + } + MemoryAttributesTable->Version = EFI_MEMORY_ATTRIBUTES_TABLE_VERSION; MemoryAttributesTable->NumberOfEntries = RuntimeEntryCount; MemoryAttributesTable->DescriptorSize = (UINT32)DescriptorSize; diff --git a/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c b/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c index 2152833ff639..bf8d33ef98aa 100644 --- a/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c +++ b/MdeModulePkg/Core/Dxe/SectionExtraction/CoreSectionExtraction.c @@ -626,7 +626,10 @@ CreateGuidedExtractionRpnEvent ( // Allocate new event structure and context // Context = AllocatePool (sizeof (RPN_EVENT_CONTEXT)); - ASSERT (Context != NULL); + if (Context == NULL) { + ASSERT (Context != NULL); + return; + } Context->ChildNode = ChildNode; Context->ParentStream = ParentStream; diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c index df6196a41cd5..8a30b037a628 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c @@ -372,7 +372,10 @@ Split2MPageTo4K ( AddressEncMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) & PAGING_1G_ADDRESS_MASK_64; PageTableEntry = AllocatePageTableMemory (1); - ASSERT (PageTableEntry != NULL); + if (PageTableEntry == NULL) { + ASSERT (PageTableEntry != NULL); + return; + } // // Fill in 2M page entry. @@ -454,7 +457,10 @@ Split1GPageTo2M ( AddressEncMask = PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) & PAGING_1G_ADDRESS_MASK_64; PageDirectoryEntry = AllocatePageTableMemory (1); - ASSERT (PageDirectoryEntry != NULL); + if (PageDirectoryEntry == NULL) { + ASSERT (PageDirectoryEntry != NULL); + return; + } // // Fill in 1G page entry. @@ -580,7 +586,10 @@ SetPageTablePoolReadOnly ( ASSERT (Level > 1); NewPageTable = AllocatePageTableMemory (1); - ASSERT (NewPageTable != NULL); + if (NewPageTable == NULL) { + ASSERT (NewPageTable != NULL); + return; + } PhysicalAddress = PageAttr & LevelMask[Level]; for (EntryIndex = 0; diff --git a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c index 79ff8d1cf9f3..ab7712a0c47d 100644 --- a/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c +++ b/MdeModulePkg/Core/Pei/Dispatcher/Dispatcher.c @@ -74,7 +74,13 @@ DiscoverPeimsAndOrderWithApriori ( TempFileHandles = AllocatePool ( sizeof (EFI_PEI_FILE_HANDLE) * (Private->TempPeimCount + TEMP_FILE_GROWTH_STEP) ); - ASSERT (TempFileHandles != NULL); + if (TempFileHandles == NULL) { + ASSERT (TempFileHandles != NULL); + Status = EFI_OUT_OF_RESOURCES; + // Let the error naturally break out of the loop + continue; + } + CopyMem ( TempFileHandles, Private->TempFileHandles, @@ -84,7 +90,13 @@ DiscoverPeimsAndOrderWithApriori ( TempFileGuid = AllocatePool ( sizeof (EFI_GUID) * (Private->TempPeimCount + TEMP_FILE_GROWTH_STEP) ); - ASSERT (TempFileGuid != NULL); + if (TempFileGuid == NULL) { + ASSERT (TempFileGuid != NULL); + Status = EFI_OUT_OF_RESOURCES; + // Let the error naturally break out of the loop + continue; + } + CopyMem ( TempFileGuid, Private->TempFileGuid, @@ -995,7 +1007,8 @@ PeiCheckAndSwitchStack ( @param PeimFileHandle Pointer to the FFS file header of the image. @param MigratedFileHandle Pointer to the FFS file header of the migrated image. - @retval EFI_SUCCESS Successfully migrated the PEIM to permanent memory. + @retval EFI_SUCCESS Successfully migrated the PEIM to permanent memory. + @retval EFI_OUT_OF_RESOURCES Insufficient memory resources for necessary internal memory allocations. **/ EFI_STATUS @@ -1022,6 +1035,11 @@ MigratePeim ( if (ImageAddress != NULL) { DEBUG_CODE_BEGIN (); AsciiString = PeCoffLoaderGetPdbPointer (ImageAddress); + if (AsciiString == NULL) { + ASSERT_EFI_ERROR (EFI_OUT_OF_RESOURCES); + return EFI_OUT_OF_RESOURCES; + } + for (Index = 0; AsciiString[Index] != 0; Index++) { if ((AsciiString[Index] == '\\') || (AsciiString[Index] == '/')) { AsciiString = AsciiString + Index + 1; @@ -1413,7 +1431,7 @@ PeiDispatcher ( { EFI_STATUS Status; UINT32 Index1; - UINT32 Index2; + UINTN Index2; CONST EFI_PEI_SERVICES **PeiServices; EFI_PEI_FILE_HANDLE PeimFileHandle; UINTN FvCount; @@ -1510,7 +1528,10 @@ PeiDispatcher ( for (FvCount = Private->CurrentPeimFvCount; FvCount < Private->FvCount; FvCount++) { CoreFvHandle = FindNextCoreFvHandle (Private, FvCount); - ASSERT (CoreFvHandle != NULL); + if (CoreFvHandle == NULL) { + ASSERT (CoreFvHandle != NULL); + continue; + } // // If the FV has corresponding EFI_PEI_FIRMWARE_VOLUME_PPI instance, then dispatch it. diff --git a/MdeModulePkg/Core/Pei/FwVol/FwVol.c b/MdeModulePkg/Core/Pei/FwVol/FwVol.c index 04bec986e42f..f3702f480e1d 100644 --- a/MdeModulePkg/Core/Pei/FwVol/FwVol.c +++ b/MdeModulePkg/Core/Pei/FwVol/FwVol.c @@ -338,7 +338,7 @@ FindFileEx ( FileOffset = (UINT32)((UINT8 *)FfsFileHeader - (UINT8 *)FwVolHeader); ASSERT (FileOffset <= 0xFFFFFFFF); - while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) { + while ((UINTN)FileOffset < (UINTN)(FvLength - sizeof (EFI_FFS_FILE_HEADER))) { // // Get FileState which is the highest bit of the State // @@ -792,7 +792,7 @@ ProcessSection ( { EFI_STATUS Status; UINT32 SectionLength; - UINT32 ParsedLength; + UINTN ParsedLength; EFI_PEI_GUIDED_SECTION_EXTRACTION_PPI *GuidSectionPpi; EFI_PEI_DECOMPRESS_PPI *DecompressPpi; VOID *PpiOutput; diff --git a/MdeModulePkg/Core/Pei/Hob/Hob.c b/MdeModulePkg/Core/Pei/Hob/Hob.c index c4882a23cde8..1416d91e68e8 100644 --- a/MdeModulePkg/Core/Pei/Hob/Hob.c +++ b/MdeModulePkg/Core/Pei/Hob/Hob.c @@ -17,7 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent @retval EFI_SUCCESS Get the pointer of HOB List @retval EFI_NOT_AVAILABLE_YET the HOB List is not yet published - @retval EFI_INVALID_PARAMETER HobList is NULL (in debug mode) + @retval EFI_INVALID_PARAMETER HobList is NULL **/ EFI_STATUS @@ -32,14 +32,10 @@ PeiGetHobList ( // // Only check this parameter in debug mode // - - DEBUG_CODE_BEGIN (); if (HobList == NULL) { return EFI_INVALID_PARAMETER; } - DEBUG_CODE_END (); - PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices); *HobList = PrivateData->HobList.Raw; diff --git a/MdeModulePkg/Core/Pei/Ppi/Ppi.c b/MdeModulePkg/Core/Pei/Ppi/Ppi.c index 0e85264ddb93..158fca9d16f5 100644 --- a/MdeModulePkg/Core/Pei/Ppi/Ppi.c +++ b/MdeModulePkg/Core/Pei/Ppi/Ppi.c @@ -163,7 +163,7 @@ ConvertPpiPointers ( IN PEI_CORE_INSTANCE *PrivateData ) { - UINT8 Index; + UINTN Index; // // Convert normal PPIs. @@ -217,7 +217,7 @@ ConvertPpiPointersFv ( IN UINTN FvSize ) { - UINT8 Index; + UINTN Index; UINTN Offset; BOOLEAN OffsetPositive; EFI_PEI_FIRMWARE_VOLUME_INFO_PPI *FvInfoPpi; @@ -324,16 +324,7 @@ ConvertPpiPointersFv ( Guid = PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi->Guid; for (GuidIndex = 0; GuidIndex < ARRAY_SIZE (GuidCheckList); ++GuidIndex) { - // - // Don't use CompareGuid function here for performance reasons. - // Instead we compare the GUID as INT32 at a time and branch - // on the first failed comparison. - // - if ((((INT32 *)Guid)[0] == ((INT32 *)GuidCheckList[GuidIndex])[0]) && - (((INT32 *)Guid)[1] == ((INT32 *)GuidCheckList[GuidIndex])[1]) && - (((INT32 *)Guid)[2] == ((INT32 *)GuidCheckList[GuidIndex])[2]) && - (((INT32 *)Guid)[3] == ((INT32 *)GuidCheckList[GuidIndex])[3])) - { + if (CompareGuid (Guid, GuidCheckList[GuidIndex]) == 0) { FvInfoPpi = PrivateData->PpiData.PpiList.PpiPtrs[Index].Ppi->Ppi; DEBUG ((DEBUG_VERBOSE, " FvInfo: %p -> ", FvInfoPpi->FvInfo)); if ((UINTN)FvInfoPpi->FvInfo == OrgFvHandle) { diff --git a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c b/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c index 28fe74ecc421..5dafdd97a229 100644 --- a/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c +++ b/MdeModulePkg/Core/PiSmmCore/MemoryAttributesTable.c @@ -433,6 +433,8 @@ SmmInstallImageRecord ( UINTN Index; EFI_SMM_DRIVER_ENTRY DriverEntry; + HandleBuffer = NULL; + Status = SmmLocateHandleBuffer ( ByProtocol, &gEfiLoadedImageProtocolGuid, @@ -469,7 +471,9 @@ SmmInstallImageRecord ( SmmInsertImageRecord (&DriverEntry); } - FreePool (HandleBuffer); + if (HandleBuffer != NULL) { + FreePool (HandleBuffer); + } } /** diff --git a/MdeModulePkg/Core/PiSmmCore/Page.c b/MdeModulePkg/Core/PiSmmCore/Page.c index 255964c23a2f..dfa9193eb190 100644 --- a/MdeModulePkg/Core/PiSmmCore/Page.c +++ b/MdeModulePkg/Core/PiSmmCore/Page.c @@ -165,7 +165,11 @@ CoreFreeMemoryMapStack ( // Deque an memory map entry from mFreeMemoryMapEntryList // Entry = AllocateMemoryMapEntry (); - ASSERT (Entry); + if (Entry == NULL) { + ASSERT (Entry); + mFreeMapStack -= 1; + return; + } // // Update to proper entry diff --git a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c index fbba868fd0b1..c658567dd34d 100644 --- a/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c +++ b/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c @@ -1433,6 +1433,9 @@ GetFullSmramRanges ( EFI_SMM_RESERVED_SMRAM_REGION *SmramReservedRanges; UINTN MaxCount; BOOLEAN Rescan; + BOOLEAN Failed; + + Failed = FALSE; // // Get SMM Configuration Protocol if it is present. @@ -1477,7 +1480,11 @@ GetFullSmramRanges ( *FullSmramRangeCount = SmramRangeCount + AdditionSmramRangeCount; Size = (*FullSmramRangeCount) * sizeof (EFI_SMRAM_DESCRIPTOR); FullSmramRanges = (EFI_SMRAM_DESCRIPTOR *)AllocateZeroPool (Size); - ASSERT (FullSmramRanges != NULL); + if (FullSmramRanges == NULL) { + ASSERT (FullSmramRanges != NULL); + Failed = TRUE; + goto Done; + } Status = mSmmAccess->GetCapabilities (mSmmAccess, &Size, FullSmramRanges); ASSERT_EFI_ERROR (Status); @@ -1524,18 +1531,34 @@ GetFullSmramRanges ( Size = MaxCount * sizeof (EFI_SMM_RESERVED_SMRAM_REGION); SmramReservedRanges = (EFI_SMM_RESERVED_SMRAM_REGION *)AllocatePool (Size); - ASSERT (SmramReservedRanges != NULL); + + if (SmramReservedRanges == NULL) { + ASSERT (SmramReservedRanges != NULL); + Failed = TRUE; + goto Done; + } + for (Index = 0; Index < SmramReservedCount; Index++) { CopyMem (&SmramReservedRanges[Index], &SmmConfiguration->SmramReservedRegions[Index], sizeof (EFI_SMM_RESERVED_SMRAM_REGION)); } Size = MaxCount * sizeof (EFI_SMRAM_DESCRIPTOR); TempSmramRanges = (EFI_SMRAM_DESCRIPTOR *)AllocatePool (Size); - ASSERT (TempSmramRanges != NULL); + if (TempSmramRanges == NULL) { + ASSERT (TempSmramRanges != NULL); + Failed = TRUE; + goto Done; + } + TempSmramRangeCount = 0; SmramRanges = (EFI_SMRAM_DESCRIPTOR *)AllocatePool (Size); - ASSERT (SmramRanges != NULL); + if (SmramRanges == NULL) { + ASSERT (SmramRanges != NULL); + Failed = TRUE; + goto Done; + } + Status = mSmmAccess->GetCapabilities (mSmmAccess, &Size, SmramRanges); ASSERT_EFI_ERROR (Status); @@ -1592,7 +1615,12 @@ GetFullSmramRanges ( // Sort the entries // FullSmramRanges = AllocateZeroPool ((TempSmramRangeCount + AdditionSmramRangeCount) * sizeof (EFI_SMRAM_DESCRIPTOR)); - ASSERT (FullSmramRanges != NULL); + if (FullSmramRanges == NULL) { + ASSERT (FullSmramRanges != NULL); + Failed = TRUE; + goto Done; + } + *FullSmramRangeCount = 0; do { for (Index = 0; Index < TempSmramRangeCount; Index++) { @@ -1616,9 +1644,22 @@ GetFullSmramRanges ( ASSERT (*FullSmramRangeCount == TempSmramRangeCount); *FullSmramRangeCount += AdditionSmramRangeCount; - FreePool (SmramRanges); - FreePool (SmramReservedRanges); - FreePool (TempSmramRanges); +Done: + if (SmramRanges != NULL) { + FreePool (SmramRanges); + } + + if (SmramReservedRanges != NULL) { + FreePool (SmramReservedRanges); + } + + if (TempSmramRanges != NULL) { + FreePool (TempSmramRanges); + } + + if (Failed) { + return NULL; + } return FullSmramRanges; } diff --git a/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c b/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c index e48532c0fb79..f202e7d6795c 100644 --- a/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c +++ b/MdeModulePkg/Core/PiSmmCore/SmiHandlerProfile.c @@ -344,7 +344,9 @@ GetSmmLoadedImage ( if (RealImageBase != 0) { PdbString = PeCoffLoaderGetPdbPointer ((VOID *)(UINTN)RealImageBase); - DEBUG ((DEBUG_INFO, " pdb - %a\n", PdbString)); + if (PdbString != NULL) { + DEBUG ((DEBUG_INFO, " pdb - %a\n", PdbString)); + } } else { PdbString = NULL; } diff --git a/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c b/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c index b437e4c43309..226d1f6d1db0 100644 --- a/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c +++ b/MdeModulePkg/Core/PiSmmCore/SmramProfileRecord.c @@ -1686,7 +1686,7 @@ SmramProfileCopyData ( LIST_ENTRY *FreePoolList; FREE_POOL_HEADER *Pool; UINTN PoolListIndex; - UINT32 Index; + UINTN Index; MEMORY_PROFILE_FREE_MEMORY *FreeMemory; MEMORY_PROFILE_MEMORY_RANGE *MemoryRange; MEMORY_PROFILE_DESCRIPTOR *MemoryProfileDescriptor; @@ -1805,7 +1805,7 @@ SmramProfileCopyData ( } } - FreeMemory->FreeMemoryEntryCount = Index; + FreeMemory->FreeMemoryEntryCount = (UINT32)Index; RemainingSize -= sizeof (MEMORY_PROFILE_FREE_MEMORY); ProfileBuffer = (UINT8 *)ProfileBuffer + sizeof (MEMORY_PROFILE_FREE_MEMORY); diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c index 19751642a30c..02c425a5576e 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenance.c @@ -539,7 +539,7 @@ UpdateTerminalContent ( IN BMM_FAKE_NV_DATA *BmmData ) { - UINT16 Index; + UINTN Index; BM_TERMINAL_CONTEXT *NewTerminalContext; BM_MENU_ENTRY *NewMenuEntry; @@ -581,7 +581,7 @@ UpdateConsoleContent ( IN BMM_FAKE_NV_DATA *BmmData ) { - UINT16 Index; + UINTN Index; BM_CONSOLE_CONTEXT *NewConsoleContext; BM_TERMINAL_CONTEXT *NewTerminalContext; BM_MENU_ENTRY *NewMenuEntry; @@ -784,7 +784,7 @@ BootMaintRouteConfig ( BMM_FAKE_NV_DATA *OldBmmData; BM_MENU_ENTRY *NewMenuEntry; BM_LOAD_CONTEXT *NewLoadContext; - UINT16 Index; + UINTN Index; BOOLEAN TerminalAttChange; BMM_CALLBACK_DATA *Private; UINTN Offset; @@ -1353,7 +1353,7 @@ DiscardChangeHandler ( IN BMM_FAKE_NV_DATA *CurrentFakeNVMap ) { - UINT16 Index; + UINTN Index; switch (Private->BmmPreviousPageId) { case FORM_BOOT_CHG_ID: @@ -1411,7 +1411,7 @@ CleanUselessBeforeSubmit ( IN BMM_CALLBACK_DATA *Private ) { - UINT16 Index; + UINTN Index; if (Private->BmmPreviousPageId != FORM_BOOT_DEL_ID) { for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) { @@ -1453,39 +1453,43 @@ CustomizeMenus ( StartOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (StartOpCodeHandle != NULL); - EndOpCodeHandle = HiiAllocateOpCodeHandle (); - ASSERT (EndOpCodeHandle != NULL); - // - // Create Hii Extend Label OpCode as the start opcode - // - StartGuidLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); - StartGuidLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; - StartGuidLabel->Number = LABEL_FORM_MAIN_START; - // - // Create Hii Extend Label OpCode as the end opcode - // - EndGuidLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); - EndGuidLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; - EndGuidLabel->Number = LABEL_FORM_MAIN_END; - - // - // Updata Front Page form - // - UiCustomizeBMMPage ( - mBmmCallbackInfo->BmmHiiHandle, - StartOpCodeHandle - ); + if (StartOpCodeHandle != NULL) { + EndOpCodeHandle = HiiAllocateOpCodeHandle (); + ASSERT (EndOpCodeHandle != NULL); + if (EndOpCodeHandle != NULL) { + // + // Create Hii Extend Label OpCode as the start opcode + // + StartGuidLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); + StartGuidLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + StartGuidLabel->Number = LABEL_FORM_MAIN_START; + // + // Create Hii Extend Label OpCode as the end opcode + // + EndGuidLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); + EndGuidLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + EndGuidLabel->Number = LABEL_FORM_MAIN_END; - HiiUpdateForm ( - mBmmCallbackInfo->BmmHiiHandle, - &mBootMaintGuid, - FORM_MAIN_ID, - StartOpCodeHandle, - EndOpCodeHandle - ); + // + // Updata Front Page form + // + UiCustomizeBMMPage ( + mBmmCallbackInfo->BmmHiiHandle, + StartOpCodeHandle + ); + + HiiUpdateForm ( + mBmmCallbackInfo->BmmHiiHandle, + &mBootMaintGuid, + FORM_MAIN_ID, + StartOpCodeHandle, + EndOpCodeHandle + ); + HiiFreeOpCodeHandle (EndOpCodeHandle); + } - HiiFreeOpCodeHandle (StartOpCodeHandle); - HiiFreeOpCodeHandle (EndOpCodeHandle); + HiiFreeOpCodeHandle (StartOpCodeHandle); + } } /** @@ -1502,7 +1506,7 @@ InitializeBmmConfig ( { BM_MENU_ENTRY *NewMenuEntry; BM_LOAD_CONTEXT *NewLoadContext; - UINT16 Index; + UINT32 Index; ASSERT (CallbackData != NULL); @@ -1510,7 +1514,7 @@ InitializeBmmConfig ( // Initialize data which located in BMM main page // CallbackData->BmmFakeNvData.BootNext = NONE_BOOTNEXT_VALUE; - for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) { + for (Index = 0; (UINTN)Index < BootOptionMenu.MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index); NewLoadContext = (BM_LOAD_CONTEXT *)NewMenuEntry->VariableContext; diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerCustomizedUiSupport.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerCustomizedUiSupport.c index e16936041a4d..34e18dea684d 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerCustomizedUiSupport.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerCustomizedUiSupport.c @@ -49,7 +49,7 @@ BmmCreateBootNextMenu ( OptionsOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (OptionsOpCodeHandle != NULL); - for (Index = 0; Index < BootOptionMenu.MenuNumber; Index++) { + for (Index = 0; (UINTN)Index < BootOptionMenu.MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&BootOptionMenu, Index); NewLoadContext = (BM_LOAD_CONTEXT *)NewMenuEntry->VariableContext; @@ -305,6 +305,8 @@ IsRequiredDriver ( UINTN TempSize; BOOLEAN RetVal; + Buffer = NULL; + Status = HiiGetFormSetFromHiiHandle (HiiHandle, &Buffer, &BufferSize); if (EFI_ERROR (Status)) { return FALSE; @@ -379,88 +381,98 @@ BmmListThirdPartyDrivers ( HiiHandles = HiiGetHiiHandles (NULL); ASSERT (HiiHandles != NULL); - - gHiiDriverList = AllocateZeroPool (UI_HII_DRIVER_LIST_SIZE * sizeof (UI_HII_DRIVER_INSTANCE)); - ASSERT (gHiiDriverList != NULL); - DriverListPtr = gHiiDriverList; - CurrentSize = UI_HII_DRIVER_LIST_SIZE; - - for (Index = 0, Count = 0; HiiHandles[Index] != NULL; Index++) { - if (!IsRequiredDriver (HiiHandles[Index], ClassGuid, &Token, &TokenHelp, &gHiiDriverList[Count].FormSetGuid)) { - continue; - } - - String = HiiGetString (HiiHandles[Index], Token, NULL); - if (String == NULL) { - String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL); - ASSERT (String != NULL); - } else if (SpecialHandlerFn != NULL) { - // - // Check whether need to rename the driver name. - // - EmptyLineAfter = FALSE; - if (SpecialHandlerFn (String, &NewName, &EmptyLineAfter)) { - FreePool (String); - String = NewName; - DriverListPtr[Count].EmptyLineAfter = EmptyLineAfter; + if (HiiHandles != NULL) { + gHiiDriverList = AllocateZeroPool (UI_HII_DRIVER_LIST_SIZE * sizeof (UI_HII_DRIVER_INSTANCE)); + ASSERT (gHiiDriverList != NULL); + if (gHiiDriverList != NULL) { + DriverListPtr = gHiiDriverList; + CurrentSize = UI_HII_DRIVER_LIST_SIZE; + + for (Index = 0, Count = 0; HiiHandles[Index] != NULL; Index++) { + if (!IsRequiredDriver (HiiHandles[Index], ClassGuid, &Token, &TokenHelp, &gHiiDriverList[Count].FormSetGuid)) { + continue; + } + + String = HiiGetString (HiiHandles[Index], Token, NULL); + if (String == NULL) { + String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL); + ASSERT (String != NULL); + } else if (SpecialHandlerFn != NULL) { + // + // Check whether need to rename the driver name. + // + EmptyLineAfter = FALSE; + if (SpecialHandlerFn (String, &NewName, &EmptyLineAfter)) { + FreePool (String); + String = NewName; + DriverListPtr[Count].EmptyLineAfter = EmptyLineAfter; + } + } + + DriverListPtr[Count].PromptId = HiiSetString (HiiHandle, 0, String, NULL); + if (String != NULL) { + FreePool (String); + } + + String = HiiGetString (HiiHandles[Index], TokenHelp, NULL); + if (String == NULL) { + String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL); + ASSERT (String != NULL); + } + + DriverListPtr[Count].HelpId = HiiSetString (HiiHandle, 0, String, NULL); + if (String != NULL) { + FreePool (String); + } + + DevicePathStr = ExtractDevicePathFromHandle (HiiHandles[Index]); + if (DevicePathStr != NULL) { + DriverListPtr[Count].DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL); + FreePool (DevicePathStr); + } else { + DriverListPtr[Count].DevicePathId = 0; + } + + Count++; + if (Count >= CurrentSize) { + DriverListPtr = ReallocatePool ( + CurrentSize * sizeof (UI_HII_DRIVER_INSTANCE), + (Count + UI_HII_DRIVER_LIST_SIZE) + * sizeof (UI_HII_DRIVER_INSTANCE), + gHiiDriverList + ); + ASSERT (DriverListPtr != NULL); + if (DriverListPtr != NULL) { + gHiiDriverList = DriverListPtr; + } + + CurrentSize += UI_HII_DRIVER_LIST_SIZE; + } } } - DriverListPtr[Count].PromptId = HiiSetString (HiiHandle, 0, String, NULL); - FreePool (String); - - String = HiiGetString (HiiHandles[Index], TokenHelp, NULL); - if (String == NULL) { - String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL); - ASSERT (String != NULL); - } - - DriverListPtr[Count].HelpId = HiiSetString (HiiHandle, 0, String, NULL); - FreePool (String); + FreePool (HiiHandles); - DevicePathStr = ExtractDevicePathFromHandle (HiiHandles[Index]); - if (DevicePathStr != NULL) { - DriverListPtr[Count].DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL); - FreePool (DevicePathStr); - } else { - DriverListPtr[Count].DevicePathId = 0; - } - - Count++; - if (Count >= CurrentSize) { - DriverListPtr = ReallocatePool ( - CurrentSize * sizeof (UI_HII_DRIVER_INSTANCE), - (Count + UI_HII_DRIVER_LIST_SIZE) - * sizeof (UI_HII_DRIVER_INSTANCE), - gHiiDriverList - ); - ASSERT (DriverListPtr != NULL); - gHiiDriverList = DriverListPtr; - CurrentSize += UI_HII_DRIVER_LIST_SIZE; - } - } - - FreePool (HiiHandles); + Index = 0; + while (gHiiDriverList[Index].PromptId != 0) { + HiiCreateGotoExOpCode ( + StartOpCodeHandle, + 0, + gHiiDriverList[Index].PromptId, + gHiiDriverList[Index].HelpId, + 0, + 0, + 0, + &gHiiDriverList[Index].FormSetGuid, + gHiiDriverList[Index].DevicePathId + ); - Index = 0; - while (gHiiDriverList[Index].PromptId != 0) { - HiiCreateGotoExOpCode ( - StartOpCodeHandle, - 0, - gHiiDriverList[Index].PromptId, - gHiiDriverList[Index].HelpId, - 0, - 0, - 0, - &gHiiDriverList[Index].FormSetGuid, - gHiiDriverList[Index].DevicePathId - ); + if (gHiiDriverList[Index].EmptyLineAfter) { + BmmCreateEmptyLine (HiiHandle, StartOpCodeHandle); + } - if (gHiiDriverList[Index].EmptyLineAfter) { - BmmCreateEmptyLine (HiiHandle, StartOpCodeHandle); + Index++; } - - Index++; } return EFI_SUCCESS; diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c index e22aaf3039f1..6f68e3f96e7d 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootOption.c @@ -813,7 +813,7 @@ GetBootOrder ( ) { BMM_FAKE_NV_DATA *BmmConfig; - UINT16 Index; + UINTN Index; UINT16 OptionOrderIndex; UINTN DeviceType; BM_MENU_ENTRY *NewMenuEntry; @@ -860,8 +860,8 @@ GetDriverOrder ( ) { BMM_FAKE_NV_DATA *BmmConfig; - UINT16 Index; - UINT16 OptionOrderIndex; + UINTN Index; + UINTN OptionOrderIndex; UINTN DeviceType; BM_MENU_ENTRY *NewMenuEntry; BM_LOAD_CONTEXT *NewLoadContext; diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/ConsoleOption.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/ConsoleOption.c index 7c02a7816601..8a4503d953c3 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/ConsoleOption.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/ConsoleOption.c @@ -803,47 +803,49 @@ GetConsoleMenu ( Index2 = 0; for (Index = 0; Index < AllCount; Index++) { DevicePathInst = GetNextDevicePathInstance (&MultiDevicePath, &Size); + ASSERT (DevicePathInst != NULL); + if (DevicePathInst != NULL) { + NewMenuEntry = BOpt_CreateMenuEntry (BM_CONSOLE_CONTEXT_SELECT); + if (NULL == NewMenuEntry) { + return EFI_OUT_OF_RESOURCES; + } - NewMenuEntry = BOpt_CreateMenuEntry (BM_CONSOLE_CONTEXT_SELECT); - if (NULL == NewMenuEntry) { - return EFI_OUT_OF_RESOURCES; - } + NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext; + NewMenuEntry->OptionNumber = Index2; - NewConsoleContext = (BM_CONSOLE_CONTEXT *)NewMenuEntry->VariableContext; - NewMenuEntry->OptionNumber = Index2; + NewConsoleContext->DevicePath = DuplicateDevicePath (DevicePathInst); + ASSERT (NewConsoleContext->DevicePath != NULL); + NewMenuEntry->DisplayString = EfiLibStrFromDatahub (NewConsoleContext->DevicePath); + if (NULL == NewMenuEntry->DisplayString) { + NewMenuEntry->DisplayString = UiDevicePathToStr (NewConsoleContext->DevicePath); + } - NewConsoleContext->DevicePath = DuplicateDevicePath (DevicePathInst); - ASSERT (NewConsoleContext->DevicePath != NULL); - NewMenuEntry->DisplayString = EfiLibStrFromDatahub (NewConsoleContext->DevicePath); - if (NULL == NewMenuEntry->DisplayString) { - NewMenuEntry->DisplayString = UiDevicePathToStr (NewConsoleContext->DevicePath); - } + NewMenuEntry->DisplayStringToken = HiiSetString (mBmmCallbackInfo->BmmHiiHandle, 0, NewMenuEntry->DisplayString, NULL); - NewMenuEntry->DisplayStringToken = HiiSetString (mBmmCallbackInfo->BmmHiiHandle, 0, NewMenuEntry->DisplayString, NULL); + if (NULL == NewMenuEntry->HelpString) { + NewMenuEntry->HelpStringToken = NewMenuEntry->DisplayStringToken; + } else { + NewMenuEntry->HelpStringToken = HiiSetString (mBmmCallbackInfo->BmmHiiHandle, 0, NewMenuEntry->HelpString, NULL); + } - if (NULL == NewMenuEntry->HelpString) { - NewMenuEntry->HelpStringToken = NewMenuEntry->DisplayStringToken; - } else { - NewMenuEntry->HelpStringToken = HiiSetString (mBmmCallbackInfo->BmmHiiHandle, 0, NewMenuEntry->HelpString, NULL); - } + NewConsoleContext->IsTerminal = IsTerminalDevicePath ( + NewConsoleContext->DevicePath, + &Terminal, + &Com + ); - NewConsoleContext->IsTerminal = IsTerminalDevicePath ( - NewConsoleContext->DevicePath, - &Terminal, - &Com + NewConsoleContext->IsActive = MatchDevicePaths ( + DevicePath, + NewConsoleContext->DevicePath ); - NewConsoleContext->IsActive = MatchDevicePaths ( - DevicePath, - NewConsoleContext->DevicePath - ); - - if (NewConsoleContext->IsTerminal) { - BOpt_DestroyMenuEntry (NewMenuEntry); - } else { - Index2++; - ConsoleMenu->MenuNumber++; - InsertTailList (&ConsoleMenu->Head, &NewMenuEntry->Link); + if (NewConsoleContext->IsTerminal) { + BOpt_DestroyMenuEntry (NewMenuEntry); + } else { + Index2++; + ConsoleMenu->MenuNumber++; + InsertTailList (&ConsoleMenu->Head, &NewMenuEntry->Link); + } } } @@ -1019,7 +1021,7 @@ GetConsoleInCheck ( IN BMM_CALLBACK_DATA *CallbackData ) { - UINT16 Index; + UINTN Index; BM_MENU_ENTRY *NewMenuEntry; UINT8 *ConInCheck; BM_CONSOLE_CONTEXT *NewConsoleContext; @@ -1057,7 +1059,7 @@ GetConsoleOutCheck ( IN BMM_CALLBACK_DATA *CallbackData ) { - UINT16 Index; + UINTN Index; BM_MENU_ENTRY *NewMenuEntry; UINT8 *ConOutCheck; BM_CONSOLE_CONTEXT *NewConsoleContext; @@ -1094,7 +1096,7 @@ GetConsoleErrCheck ( IN BMM_CALLBACK_DATA *CallbackData ) { - UINT16 Index; + UINTN Index; BM_MENU_ENTRY *NewMenuEntry; UINT8 *ConErrCheck; BM_CONSOLE_CONTEXT *NewConsoleContext; @@ -1134,7 +1136,7 @@ GetTerminalAttribute ( BMM_FAKE_NV_DATA *CurrentFakeNVMap; BM_MENU_ENTRY *NewMenuEntry; BM_TERMINAL_CONTEXT *NewTerminalContext; - UINT16 TerminalIndex; + UINTN TerminalIndex; UINT8 AttributeIndex; ASSERT (CallbackData != NULL); diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c index b1d1e2ee44f4..d2e2d416f678 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c @@ -200,7 +200,7 @@ UpdateConCOMPage ( UpdatePageStart (CallbackData); - for (Index = 0; Index < TerminalMenu.MenuNumber; Index++) { + for (Index = 0; (UINTN)Index < TerminalMenu.MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&TerminalMenu, Index); HiiCreateGotoOpCode ( @@ -230,7 +230,7 @@ UpdateBootDelPage ( { BM_MENU_ENTRY *NewMenuEntry; BM_LOAD_CONTEXT *NewLoadContext; - UINT16 Index; + UINTN Index; CallbackData->BmmAskSaveOrNot = TRUE; @@ -291,7 +291,7 @@ UpdateDrvAddHandlePage ( UpdatePageStart (CallbackData); - for (Index = 0; Index < DriverMenu.MenuNumber; Index++) { + for (Index = 0; (UINTN)Index < DriverMenu.MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&DriverMenu, Index); HiiCreateGotoOpCode ( @@ -328,7 +328,7 @@ UpdateDrvDelPage ( UpdatePageStart (CallbackData); ASSERT (DriverOptionMenu.MenuNumber <= (sizeof (CallbackData->BmmFakeNvData.DriverOptionDel) / sizeof (CallbackData->BmmFakeNvData.DriverOptionDel[0]))); - for (Index = 0; Index < DriverOptionMenu.MenuNumber; Index++) { + for (Index = 0; (UINTN)Index < DriverOptionMenu.MenuNumber; Index++) { NewMenuEntry = BOpt_GetMenuEntry (&DriverOptionMenu, Index); NewLoadContext = (BM_LOAD_CONTEXT *)NewMenuEntry->VariableContext; @@ -488,7 +488,7 @@ UpdateConsolePage ( ASSERT (ConsoleCheck != NULL); - for (Index = 0; ((Index < ConsoleMenu->MenuNumber) && \ + for (Index = 0; (((UINTN)Index < ConsoleMenu->MenuNumber) && \ (Index < MAX_MENU_NUMBER)); Index++) { CheckFlags = 0; @@ -514,7 +514,7 @@ UpdateConsolePage ( ); } - for (Index2 = 0; ((Index2 < TerminalMenu.MenuNumber) && \ + for (Index2 = 0; (((UINTN)Index2 < TerminalMenu.MenuNumber) && \ (Index2 < MAX_MENU_NUMBER)); Index2++) { CheckFlags = 0; @@ -571,7 +571,7 @@ UpdateOrderPage ( ) { BM_MENU_ENTRY *NewMenuEntry; - UINT16 Index; + UINTN Index; UINT16 OptionIndex; VOID *OptionsOpCodeHandle; BOOLEAN BootOptionFound; diff --git a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c index 82a0ed66a714..53b71a8ca1d2 100644 --- a/MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c +++ b/MdeModulePkg/Library/BootMaintenanceManagerUiLib/Variable.c @@ -198,11 +198,13 @@ Var_UpdateConsoleOption ( (EFI_DEVICE_PATH_PROTOCOL *)&Vendor ); ASSERT (TerminalDevicePath != NULL); - ChangeTerminalDevicePath (TerminalDevicePath, TRUE); - ConDevicePath = AppendDevicePathInstance ( - ConDevicePath, - TerminalDevicePath - ); + if (TerminalDevicePath != NULL) { + ChangeTerminalDevicePath (TerminalDevicePath, TRUE); + ConDevicePath = AppendDevicePathInstance ( + ConDevicePath, + TerminalDevicePath + ); + } } } @@ -537,7 +539,7 @@ Var_UpdateBootNext ( BM_MENU_ENTRY *NewMenuEntry; BM_LOAD_CONTEXT *NewLoadContext; BMM_FAKE_NV_DATA *CurrentFakeNVMap; - UINT16 Index; + UINTN Index; EFI_STATUS Status; Status = EFI_SUCCESS; @@ -592,8 +594,8 @@ Var_UpdateBootOrder ( ) { EFI_STATUS Status; - UINT16 Index; - UINT16 OrderIndex; + UINTN Index; + UINTN OrderIndex; UINT16 *BootOrder; UINTN BootOrderSize; UINT16 OptionNumber; @@ -654,7 +656,7 @@ Var_UpdateDriverOrder ( ) { EFI_STATUS Status; - UINT16 Index; + UINTN Index; UINT16 *DriverOrderList; UINT16 *NewDriverOrderList; UINTN DriverOrderListSize; diff --git a/MdeModulePkg/Library/BootManagerUiLib/BootManager.c b/MdeModulePkg/Library/BootManagerUiLib/BootManager.c index b7526796d6e1..976e7c209dea 100644 --- a/MdeModulePkg/Library/BootManagerUiLib/BootManager.c +++ b/MdeModulePkg/Library/BootManagerUiLib/BootManager.c @@ -518,108 +518,114 @@ UpdateBootManager ( // StartOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (StartOpCodeHandle != NULL); + if (StartOpCodeHandle != NULL) { + EndOpCodeHandle = HiiAllocateOpCodeHandle (); + ASSERT (EndOpCodeHandle != NULL); + if (EndOpCodeHandle != NULL) { + // + // Create Hii Extend Label OpCode as the start opcode + // + StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); + StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + StartLabel->Number = LABEL_BOOT_OPTION; - EndOpCodeHandle = HiiAllocateOpCodeHandle (); - ASSERT (EndOpCodeHandle != NULL); - - // - // Create Hii Extend Label OpCode as the start opcode - // - StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); - StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; - StartLabel->Number = LABEL_BOOT_OPTION; + // + // Create Hii Extend Label OpCode as the end opcode + // + EndLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); + EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + EndLabel->Number = LABEL_BOOT_OPTION_END; + mKeyInput = 0; + NeedEndOp = FALSE; + for (Index = 0; Index < BootOptionCount; Index++) { + // + // At this stage we are creating a menu entry, thus the Keys are reproduceable + // + mKeyInput++; - // - // Create Hii Extend Label OpCode as the end opcode - // - EndLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); - EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; - EndLabel->Number = LABEL_BOOT_OPTION_END; - mKeyInput = 0; - NeedEndOp = FALSE; - for (Index = 0; Index < BootOptionCount; Index++) { - // - // At this stage we are creating a menu entry, thus the Keys are reproduceable - // - mKeyInput++; + // + // Don't display hidden boot options, but retain inactive ones. + // + if ((BootOption[Index].Attributes & LOAD_OPTION_HIDDEN) != 0) { + continue; + } - // - // Don't display hidden boot options, but retain inactive ones. - // - if ((BootOption[Index].Attributes & LOAD_OPTION_HIDDEN) != 0) { - continue; - } + // + // Group the legacy boot option in the sub title created dynamically + // + IsLegacyOption = (BOOLEAN)( + (DevicePathType (BootOption[Index].FilePath) == BBS_DEVICE_PATH) && + (DevicePathSubType (BootOption[Index].FilePath) == BBS_BBS_DP) + ); + + if (!IsLegacyOption && NeedEndOp) { + NeedEndOp = FALSE; + HiiCreateEndOpCode (StartOpCodeHandle); + } - // - // Group the legacy boot option in the sub title created dynamically - // - IsLegacyOption = (BOOLEAN)( - (DevicePathType (BootOption[Index].FilePath) == BBS_DEVICE_PATH) && - (DevicePathSubType (BootOption[Index].FilePath) == BBS_BBS_DP) - ); + if (IsLegacyOption && (DeviceType != ((BBS_BBS_DEVICE_PATH *)BootOption[Index].FilePath)->DeviceType)) { + if (NeedEndOp) { + HiiCreateEndOpCode (StartOpCodeHandle); + } - if (!IsLegacyOption && NeedEndOp) { - NeedEndOp = FALSE; - HiiCreateEndOpCode (StartOpCodeHandle); - } + DeviceType = ((BBS_BBS_DEVICE_PATH *)BootOption[Index].FilePath)->DeviceType; + Token = HiiSetString ( + HiiHandle, + 0, + mDeviceTypeStr[ + MIN (DeviceType & 0xF, ARRAY_SIZE (mDeviceTypeStr) - 1) + ], + NULL + ); + HiiCreateSubTitleOpCode (StartOpCodeHandle, Token, 0, 0, 1); + NeedEndOp = TRUE; + } - if (IsLegacyOption && (DeviceType != ((BBS_BBS_DEVICE_PATH *)BootOption[Index].FilePath)->DeviceType)) { - if (NeedEndOp) { - HiiCreateEndOpCode (StartOpCodeHandle); - } + ASSERT (BootOption[Index].Description != NULL); - DeviceType = ((BBS_BBS_DEVICE_PATH *)BootOption[Index].FilePath)->DeviceType; - Token = HiiSetString ( - HiiHandle, - 0, - mDeviceTypeStr[ - MIN (DeviceType & 0xF, ARRAY_SIZE (mDeviceTypeStr) - 1) - ], - NULL - ); - HiiCreateSubTitleOpCode (StartOpCodeHandle, Token, 0, 0, 1); - NeedEndOp = TRUE; - } + Token = HiiSetString (HiiHandle, 0, BootOption[Index].Description, NULL); - ASSERT (BootOption[Index].Description != NULL); + TempStr = BmDevicePathToStr (BootOption[Index].FilePath); + if (TempStr != NULL) { + TempSize = StrSize (TempStr); + HelpString = AllocateZeroPool (TempSize + StrSize (L"Device Path : ")); + MaxLen = (TempSize + StrSize (L"Device Path : "))/sizeof (CHAR16); + ASSERT (HelpString != NULL); + if (HelpString != NULL) { + StrCatS (HelpString, MaxLen, L"Device Path : "); + StrCatS (HelpString, MaxLen, TempStr); + } + } - Token = HiiSetString (HiiHandle, 0, BootOption[Index].Description, NULL); + HelpToken = HiiSetString (HiiHandle, 0, HelpString, NULL); - TempStr = BmDevicePathToStr (BootOption[Index].FilePath); - TempSize = StrSize (TempStr); - HelpString = AllocateZeroPool (TempSize + StrSize (L"Device Path : ")); - MaxLen = (TempSize + StrSize (L"Device Path : "))/sizeof (CHAR16); - ASSERT (HelpString != NULL); - StrCatS (HelpString, MaxLen, L"Device Path : "); - StrCatS (HelpString, MaxLen, TempStr); + HiiCreateActionOpCode ( + StartOpCodeHandle, + mKeyInput, + Token, + HelpToken, + EFI_IFR_FLAG_CALLBACK, + 0 + ); + } - HelpToken = HiiSetString (HiiHandle, 0, HelpString, NULL); + if (NeedEndOp) { + HiiCreateEndOpCode (StartOpCodeHandle); + } - HiiCreateActionOpCode ( - StartOpCodeHandle, - mKeyInput, - Token, - HelpToken, - EFI_IFR_FLAG_CALLBACK, - 0 - ); - } + HiiUpdateForm ( + HiiHandle, + &mBootManagerGuid, + BOOT_MANAGER_FORM_ID, + StartOpCodeHandle, + EndOpCodeHandle + ); + HiiFreeOpCodeHandle (EndOpCodeHandle); + } - if (NeedEndOp) { - HiiCreateEndOpCode (StartOpCodeHandle); + HiiFreeOpCodeHandle (StartOpCodeHandle); } - HiiUpdateForm ( - HiiHandle, - &mBootManagerGuid, - BOOT_MANAGER_FORM_ID, - StartOpCodeHandle, - EndOpCodeHandle - ); - - HiiFreeOpCodeHandle (StartOpCodeHandle); - HiiFreeOpCodeHandle (EndOpCodeHandle); - EfiBootManagerFreeLoadOptions (BootOption, BootOptionCount); } @@ -839,10 +845,14 @@ BootManagerCallback ( // parse the selected option // BmSetConsoleMode (FALSE); - EfiBootManagerBoot (&BootOption[QuestionId - 1]); + + if (BootOption != NULL) { + EfiBootManagerBoot (&BootOption[QuestionId - 1]); + } + BmSetConsoleMode (TRUE); - if (EFI_ERROR (BootOption[QuestionId - 1].Status)) { + if ((BootOption != NULL) && EFI_ERROR (BootOption[QuestionId - 1].Status)) { gST->ConOut->OutputString ( gST->ConOut, HiiGetString (gBootManagerPrivate.HiiHandle, STRING_TOKEN (STR_ANY_KEY_CONTINUE), NULL) diff --git a/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompress.c b/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompress.c index 3cb31ab98467..4e71c210a37b 100644 --- a/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompress.c +++ b/MdeModulePkg/Library/BrotliCustomDecompressLib/BrotliDecompress.c @@ -182,12 +182,12 @@ BrGetDecodedSizeOfBuf ( ) { UINT64 DecodedSize; - INTN Index; + UINT8 Index; /* Parse header */ DecodedSize = 0; - for (Index = EndOffset - 1; Index >= StartOffset; Index--) { - DecodedSize = LShiftU64 (DecodedSize, 8) + EncodedData[Index]; + for (Index = EndOffset; Index > StartOffset; Index--) { + DecodedSize = LShiftU64 (DecodedSize, 8) + EncodedData[Index - 1]; } return DecodedSize; diff --git a/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.c b/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.c index 58130d93838c..7e9cbeb62c7a 100644 --- a/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.c +++ b/MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLibInternal.c @@ -68,12 +68,12 @@ PrintBannerInfo ( // // for (Line = 0; Line < BANNER_HEIGHT; Line++) { // - for (Line = (UINT8)gScreenDimensions.TopRow; Line < BANNER_HEIGHT + (UINT8)gScreenDimensions.TopRow; Line++) { + for (Line = (UINT8)gScreenDimensions.TopRow; (UINTN)Line < (UINTN)(BANNER_HEIGHT + (UINT8)gScreenDimensions.TopRow); Line++) { // // for (Alignment = 0; Alignment < BANNER_COLUMNS; Alignment++) { // for (Alignment = (UINT8)gScreenDimensions.LeftColumn; - Alignment < BANNER_COLUMNS + (UINT8)gScreenDimensions.LeftColumn; + (UINTN)Alignment < (UINTN)(BANNER_COLUMNS + (UINT8)gScreenDimensions.LeftColumn); Alignment++ ) { diff --git a/MdeModulePkg/Library/DeviceManagerUiLib/DeviceManager.c b/MdeModulePkg/Library/DeviceManagerUiLib/DeviceManager.c index c8ca25e87f8a..2c313a9b1d68 100644 --- a/MdeModulePkg/Library/DeviceManagerUiLib/DeviceManager.c +++ b/MdeModulePkg/Library/DeviceManagerUiLib/DeviceManager.c @@ -557,10 +557,14 @@ CreateDeviceManagerForm ( NewStringLen = StrLen (mSelectedMacAddrString) * 2; NewStringLen += (StrLen (String) + 2) * 2; NewStringTitle = AllocatePool (NewStringLen); - UnicodeSPrint (NewStringTitle, NewStringLen, L"%s %s", String, mSelectedMacAddrString); - HiiSetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NewStringTitle, NULL); + + if (NewStringTitle != NULL) { + UnicodeSPrint (NewStringTitle, NewStringLen, L"%s %s", String, mSelectedMacAddrString); + HiiSetString (HiiHandle, STRING_TOKEN (STR_FORM_NETWORK_DEVICE_TITLE), NewStringTitle, NULL); + FreePool (NewStringTitle); + } + FreePool (String); - FreePool (NewStringTitle); } // @@ -568,184 +572,194 @@ CreateDeviceManagerForm ( // StartOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (StartOpCodeHandle != NULL); + if (StartOpCodeHandle != NULL) { + EndOpCodeHandle = HiiAllocateOpCodeHandle (); + ASSERT (EndOpCodeHandle != NULL); + if (EndOpCodeHandle != NULL) { + // + // Create Hii Extend Label OpCode as the start opcode + // + StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); + StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + // + // According to the next show Form id(mNextShowFormId) to decide which form need to update. + // + StartLabel->Number = (UINT16)(LABEL_FORM_ID_OFFSET + NextShowFormId); - EndOpCodeHandle = HiiAllocateOpCodeHandle (); - ASSERT (EndOpCodeHandle != NULL); - - // - // Create Hii Extend Label OpCode as the start opcode - // - StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); - StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; - // - // According to the next show Form id(mNextShowFormId) to decide which form need to update. - // - StartLabel->Number = (UINT16)(LABEL_FORM_ID_OFFSET + NextShowFormId); - - // - // Create Hii Extend Label OpCode as the end opcode - // - EndLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); - EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; - EndLabel->Number = LABEL_END; - - // - // Get all the Hii handles - // - HiiHandles = HiiGetHiiHandles (NULL); - ASSERT (HiiHandles != NULL); - - // - // Search for formset of each class type - // - for (Index = 0; HiiHandles[Index] != NULL; Index++) { - Status = HiiGetFormSetFromHiiHandle (HiiHandles[Index], &Buffer, &BufferSize); - if (EFI_ERROR (Status)) { - continue; - } - - Ptr = (UINT8 *)Buffer; - while (TempSize < BufferSize) { - TempSize += ((EFI_IFR_OP_HEADER *)Ptr)->Length; - if (((EFI_IFR_OP_HEADER *)Ptr)->Length <= OFFSET_OF (EFI_IFR_FORM_SET, Flags)) { - Ptr += ((EFI_IFR_OP_HEADER *)Ptr)->Length; - continue; - } - - ClassGuidNum = (UINT8)(((EFI_IFR_FORM_SET *)Ptr)->Flags & 0x3); - ClassGuid = (EFI_GUID *)(VOID *)(Ptr + sizeof (EFI_IFR_FORM_SET)); - while (ClassGuidNum-- > 0) { - if (CompareGuid (&gEfiHiiPlatformSetupFormsetGuid, ClassGuid) == 0) { - ClassGuid++; - continue; - } - - String = HiiGetString (HiiHandles[Index], ((EFI_IFR_FORM_SET *)Ptr)->FormSetTitle, NULL); - if (String == NULL) { - String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL); - ASSERT (String != NULL); - } - - Token = HiiSetString (HiiHandle, 0, String, NULL); - FreePool (String); - - String = HiiGetString (HiiHandles[Index], ((EFI_IFR_FORM_SET *)Ptr)->Help, NULL); - if (String == NULL) { - String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL); - ASSERT (String != NULL); - } - - TokenHelp = HiiSetString (HiiHandle, 0, String, NULL); - FreePool (String); - - CopyMem (&FormSetGuid, &((EFI_IFR_FORM_SET *)Ptr)->Guid, sizeof (EFI_GUID)); + // + // Create Hii Extend Label OpCode as the end opcode + // + EndLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL)); + EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + EndLabel->Number = LABEL_END; + // + // Get all the Hii handles + // + HiiHandles = HiiGetHiiHandles (NULL); + ASSERT (HiiHandles != NULL); + if (HiiHandles != NULL) { // - // Network device process + // Search for formset of each class type // - if (IsNeedAddNetworkMenu (HiiHandles[Index], NextShowFormId, &AddItemCount)) { - if (NextShowFormId == DEVICE_MANAGER_FORM_ID) { - // - // Only show one menu item "Network Config" in the device manger form. - // - if (!AddNetworkMenu) { - AddNetworkMenu = TRUE; - HiiCreateGotoOpCode ( - StartOpCodeHandle, - NETWORK_DEVICE_LIST_FORM_ID, - STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_TITLE), - STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_HELP), - EFI_IFR_FLAG_CALLBACK, - (EFI_QUESTION_ID)QUESTION_NETWORK_DEVICE_ID - ); - } - } else if (NextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) { - // - // In network device list form, same mac address device only show one menu. - // - while (AddItemCount > 0) { - HiiCreateGotoOpCode ( - StartOpCodeHandle, - NETWORK_DEVICE_FORM_ID, - mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].PromptId, - STRING_TOKEN (STR_NETWORK_DEVICE_HELP), - EFI_IFR_FLAG_CALLBACK, - mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].QuestionId - ); - AddItemCount -= 1; - } - } else if (NextShowFormId == NETWORK_DEVICE_FORM_ID) { - // - // In network device form, only the selected mac address device need to be show. - // - DevicePathStr = DmExtractDevicePathFromHiiHandle (HiiHandles[Index]); - DevicePathId = 0; - if (DevicePathStr != NULL) { - DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL); - FreePool (DevicePathStr); + for (Index = 0; HiiHandles[Index] != NULL; Index++) { + Status = HiiGetFormSetFromHiiHandle (HiiHandles[Index], &Buffer, &BufferSize); + if (EFI_ERROR (Status)) { + continue; + } + + Ptr = (UINT8 *)Buffer; + while (TempSize < BufferSize) { + TempSize += ((EFI_IFR_OP_HEADER *)Ptr)->Length; + if (((EFI_IFR_OP_HEADER *)Ptr)->Length <= OFFSET_OF (EFI_IFR_FORM_SET, Flags)) { + Ptr += ((EFI_IFR_OP_HEADER *)Ptr)->Length; + continue; } - HiiCreateGotoExOpCode ( - StartOpCodeHandle, - 0, - Token, - TokenHelp, - 0, - (EFI_QUESTION_ID)(Index + DEVICE_KEY_OFFSET), - 0, - &FormSetGuid, - DevicePathId - ); - } - } else { - // - // Not network device process, only need to show at device manger form. - // - if (NextShowFormId == DEVICE_MANAGER_FORM_ID) { - DevicePathStr = DmExtractDevicePathFromHiiHandle (HiiHandles[Index]); - DevicePathId = 0; - if (DevicePathStr != NULL) { - DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL); - FreePool (DevicePathStr); + ClassGuidNum = (UINT8)(((EFI_IFR_FORM_SET *)Ptr)->Flags & 0x3); + ClassGuid = (EFI_GUID *)(VOID *)(Ptr + sizeof (EFI_IFR_FORM_SET)); + while (ClassGuidNum-- > 0) { + if (CompareGuid (&gEfiHiiPlatformSetupFormsetGuid, ClassGuid) == 0) { + ClassGuid++; + continue; + } + + String = HiiGetString (HiiHandles[Index], ((EFI_IFR_FORM_SET *)Ptr)->FormSetTitle, NULL); + if (String == NULL) { + String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL); + ASSERT (String != NULL); + } + + Token = HiiSetString (HiiHandle, 0, String, NULL); + if (String != NULL) { + FreePool (String); + } + + String = HiiGetString (HiiHandles[Index], ((EFI_IFR_FORM_SET *)Ptr)->Help, NULL); + if (String == NULL) { + String = HiiGetString (HiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL); + ASSERT (String != NULL); + } + + TokenHelp = HiiSetString (HiiHandle, 0, String, NULL); + if (String != NULL) { + FreePool (String); + } + + CopyMem (&FormSetGuid, &((EFI_IFR_FORM_SET *)Ptr)->Guid, sizeof (EFI_GUID)); + + // + // Network device process + // + if (IsNeedAddNetworkMenu (HiiHandles[Index], NextShowFormId, &AddItemCount)) { + if (NextShowFormId == DEVICE_MANAGER_FORM_ID) { + // + // Only show one menu item "Network Config" in the device manger form. + // + if (!AddNetworkMenu) { + AddNetworkMenu = TRUE; + HiiCreateGotoOpCode ( + StartOpCodeHandle, + NETWORK_DEVICE_LIST_FORM_ID, + STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_TITLE), + STRING_TOKEN (STR_FORM_NETWORK_DEVICE_LIST_HELP), + EFI_IFR_FLAG_CALLBACK, + (EFI_QUESTION_ID)QUESTION_NETWORK_DEVICE_ID + ); + } + } else if (NextShowFormId == NETWORK_DEVICE_LIST_FORM_ID) { + // + // In network device list form, same mac address device only show one menu. + // + while (AddItemCount > 0) { + HiiCreateGotoOpCode ( + StartOpCodeHandle, + NETWORK_DEVICE_FORM_ID, + mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].PromptId, + STRING_TOKEN (STR_NETWORK_DEVICE_HELP), + EFI_IFR_FLAG_CALLBACK, + mMacDeviceList.NodeList[mMacDeviceList.CurListLen - AddItemCount].QuestionId + ); + AddItemCount -= 1; + } + } else if (NextShowFormId == NETWORK_DEVICE_FORM_ID) { + // + // In network device form, only the selected mac address device need to be show. + // + DevicePathStr = DmExtractDevicePathFromHiiHandle (HiiHandles[Index]); + DevicePathId = 0; + if (DevicePathStr != NULL) { + DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL); + FreePool (DevicePathStr); + } + + HiiCreateGotoExOpCode ( + StartOpCodeHandle, + 0, + Token, + TokenHelp, + 0, + (EFI_QUESTION_ID)(Index + DEVICE_KEY_OFFSET), + 0, + &FormSetGuid, + DevicePathId + ); + } + } else { + // + // Not network device process, only need to show at device manger form. + // + if (NextShowFormId == DEVICE_MANAGER_FORM_ID) { + DevicePathStr = DmExtractDevicePathFromHiiHandle (HiiHandles[Index]); + DevicePathId = 0; + if (DevicePathStr != NULL) { + DevicePathId = HiiSetString (HiiHandle, 0, DevicePathStr, NULL); + FreePool (DevicePathStr); + } + + HiiCreateGotoExOpCode ( + StartOpCodeHandle, + 0, + Token, + TokenHelp, + 0, + (EFI_QUESTION_ID)(Index + DEVICE_KEY_OFFSET), + 0, + &FormSetGuid, + DevicePathId + ); + } + } + + break; } - HiiCreateGotoExOpCode ( - StartOpCodeHandle, - 0, - Token, - TokenHelp, - 0, - (EFI_QUESTION_ID)(Index + DEVICE_KEY_OFFSET), - 0, - &FormSetGuid, - DevicePathId - ); + Ptr += ((EFI_IFR_OP_HEADER *)Ptr)->Length; } - } - break; + FreePool (Buffer); + Buffer = NULL; + TempSize = 0; + BufferSize = 0; + } } - Ptr += ((EFI_IFR_OP_HEADER *)Ptr)->Length; + HiiUpdateForm ( + HiiHandle, + &mDeviceManagerGuid, + NextShowFormId, + StartOpCodeHandle, + EndOpCodeHandle + ); + HiiFreeOpCodeHandle (EndOpCodeHandle); } - FreePool (Buffer); - Buffer = NULL; - TempSize = 0; - BufferSize = 0; + HiiFreeOpCodeHandle (StartOpCodeHandle); } - HiiUpdateForm ( - HiiHandle, - &mDeviceManagerGuid, - NextShowFormId, - StartOpCodeHandle, - EndOpCodeHandle - ); - - HiiFreeOpCodeHandle (StartOpCodeHandle); - HiiFreeOpCodeHandle (EndOpCodeHandle); - FreePool (HiiHandles); + if (HiiHandles != NULL) { + FreePool (HiiHandles); + } } /** diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/CapsuleOnDisk.c b/MdeModulePkg/Library/DxeCapsuleLibFmp/CapsuleOnDisk.c index 41b3282d293e..a69c2365cce6 100644 --- a/MdeModulePkg/Library/DxeCapsuleLibFmp/CapsuleOnDisk.c +++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/CapsuleOnDisk.c @@ -301,7 +301,7 @@ GetBootOptionInOrder ( // Second get BootOption from "BootOrder" // BootOrderOptionBuf = EfiBootManagerGetLoadOptions (&BootOrderCount, LoadOptionTypeBoot); - if ((BootNextCount == 0) && (BootOrderCount == 0)) { + if (((BootNextCount == 0) && (BootOrderCount == 0)) || (BootOrderOptionBuf == NULL)) { return EFI_NOT_FOUND; } diff --git a/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c b/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c index ef32771561dc..3fccfb99747a 100644 --- a/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c +++ b/MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c @@ -1053,7 +1053,11 @@ InsertFpdtRecord ( switch (PerfId) { case MODULE_START_ID: case MODULE_END_ID: - GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid); + Status = GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to get Module Info from Handle! Status = %r\n", Status)); + } + StringPtr = ModuleName; // // Cache the offset of start image start record and use to update the start image end record if needed. @@ -1089,7 +1093,11 @@ InsertFpdtRecord ( case MODULE_LOADIMAGE_START_ID: case MODULE_LOADIMAGE_END_ID: - GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid); + Status = GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to get Module Info from Handle! Status = %r\n", Status)); + } + StringPtr = ModuleName; if (PerfId == MODULE_LOADIMAGE_START_ID) { mLoadImageCount++; @@ -1132,7 +1140,11 @@ InsertFpdtRecord ( case MODULE_DB_SUPPORT_END_ID: case MODULE_DB_STOP_START_ID: case MODULE_DB_STOP_END_ID: - GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid); + Status = GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to get Module Info from Handle! Status = %r\n", Status)); + } + StringPtr = ModuleName; if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) { FpdtRecordPtr.GuidQwordEvent->Header.Type = FPDT_GUID_QWORD_EVENT_TYPE; @@ -1147,7 +1159,11 @@ InsertFpdtRecord ( break; case MODULE_DB_END_ID: - GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid); + Status = GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to get Module Info from Handle! Status = %r\n", Status)); + } + StringPtr = ModuleName; if (!PcdGetBool (PcdEdkiiFpdtStringRecordEnableOnly)) { FpdtRecordPtr.GuidQwordStringEvent->Header.Type = FPDT_GUID_QWORD_STRING_EVENT_TYPE; @@ -1197,14 +1213,20 @@ InsertFpdtRecord ( case PERF_INMODULE_END_ID: case PERF_CROSSMODULE_START_ID: case PERF_CROSSMODULE_END_ID: - GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid); + Status = GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to get Module Info from Handle! Status = %r\n", Status)); + } + + StringPtr = NULL; + if (String != NULL) { StringPtr = String; - } else { + } else if (ModuleName != NULL) { StringPtr = ModuleName; } - if (AsciiStrLen (StringPtr) == 0) { + if ((StringPtr == NULL) || (AsciiStrLen (StringPtr) == 0)) { StringPtr = "unknown name"; } @@ -1222,14 +1244,20 @@ InsertFpdtRecord ( default: if (Attribute != PerfEntry) { - GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid); + Status = GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to get Module Info from Handle! Status = %r\n", Status)); + } + + StringPtr = NULL; + if (String != NULL) { StringPtr = String; - } else { + } else if (ModuleName != NULL) { StringPtr = ModuleName; } - if (AsciiStrLen (StringPtr) == 0) { + if ((StringPtr == NULL) || (AsciiStrLen (StringPtr) == 0)) { StringPtr = "unknown name"; } diff --git a/MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.c b/MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.c index 8b8cf3a7d3e4..c89cf9f985a7 100644 --- a/MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.c +++ b/MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.c @@ -220,7 +220,7 @@ ExecuteSecurityHandlers ( UINTN FileSize; EFI_HANDLE Handle; EFI_DEVICE_PATH_PROTOCOL *Node; - EFI_DEVICE_PATH_PROTOCOL *FilePathToVerfiy; + EFI_DEVICE_PATH_PROTOCOL *FilePathToVerify; if (FilePath == NULL) { return EFI_INVALID_PARAMETER; @@ -237,7 +237,7 @@ ExecuteSecurityHandlers ( FileBuffer = NULL; FileSize = 0; HandlerAuthenticationStatus = AuthenticationStatus; - FilePathToVerfiy = (EFI_DEVICE_PATH_PROTOCOL *)FilePath; + FilePathToVerify = (EFI_DEVICE_PATH_PROTOCOL *)FilePath; // // Run security handler in same order to their registered list // @@ -247,7 +247,7 @@ ExecuteSecurityHandlers ( // Try get file buffer when the handler requires image buffer. // if (FileBuffer == NULL) { - Node = FilePathToVerfiy; + Node = FilePathToVerify; Status = gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &Node, &Handle); // // Try to get image by FALSE boot policy for the exact boot file path. @@ -264,14 +264,19 @@ ExecuteSecurityHandlers ( // // LoadFile () may cause the device path of the Handle be updated. // - FilePathToVerfiy = AppendDevicePath (DevicePathFromHandle (Handle), Node); + FilePathToVerify = AppendDevicePath (DevicePathFromHandle (Handle), Node); } } } + if (FilePathToVerify == NULL) { + ASSERT (FilePathToVerify != NULL); + continue; + } + Status = mSecurityTable[Index].SecurityHandler ( HandlerAuthenticationStatus, - FilePathToVerfiy, + FilePathToVerify, FileBuffer, FileSize ); @@ -284,8 +289,8 @@ ExecuteSecurityHandlers ( FreePool (FileBuffer); } - if (FilePathToVerfiy != FilePath) { - FreePool (FilePathToVerfiy); + if (FilePathToVerify != FilePath) { + FreePool (FilePathToVerify); } return Status; diff --git a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c index 804a03d868f2..561b11654f4d 100644 --- a/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c +++ b/MdeModulePkg/Library/FileExplorerLib/FileExplorer.c @@ -560,7 +560,11 @@ LibFileInfo ( ); if (Status == EFI_BUFFER_TOO_SMALL) { Buffer = AllocatePool (BufferSize); - ASSERT (Buffer != NULL); + + if (Buffer == NULL) { + ASSERT (Buffer != NULL); + return NULL; + } } Status = FHand->GetInfo ( @@ -1075,6 +1079,11 @@ LibCreateNewFile ( NewHandle = NULL; FullFileName = NULL; + Status = LibGetFileHandleFromDevicePath (gFileExplorerPrivate.RetDevicePath, &FileHandle, &ParentName, &DeviceHandle); + if (EFI_ERROR (Status)) { + return EFI_NOT_FOUND; + } + if (EFI_ERROR (LibGetFileHandleFromDevicePath (gFileExplorerPrivate.RetDevicePath, &FileHandle, &ParentName, &DeviceHandle))) { return EFI_DEVICE_ERROR; } diff --git a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c index 2700f5adbcf5..cc62dc7f31a3 100644 --- a/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c +++ b/MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c @@ -694,14 +694,20 @@ InsertFpdtRecord ( case PERF_INMODULE_END_ID: case PERF_CROSSMODULE_START_ID: case PERF_CROSSMODULE_END_ID: - GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid); + Status = GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to get Module Info from Handle! Status = %r\n", Status)); + } + + StringPtr = NULL; + if (String != NULL) { StringPtr = String; - } else { + } else if (ModuleName != NULL) { StringPtr = ModuleName; } - if (AsciiStrLen (StringPtr) == 0) { + if ((StringPtr == NULL) || (AsciiStrLen (StringPtr) == 0)) { StringPtr = "unknown name"; } @@ -719,14 +725,20 @@ InsertFpdtRecord ( default: if (Attribute != PerfEntry) { - GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid); + Status = GetModuleInfoFromHandle ((EFI_HANDLE)CallerIdentifier, ModuleName, sizeof (ModuleName), &ModuleGuid); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to get Module Info from Handle! Status = %r\n", Status)); + } + + StringPtr = NULL; + if (String != NULL) { StringPtr = String; - } else { + } else if (ModuleName != NULL) { StringPtr = ModuleName; } - if (AsciiStrLen (StringPtr) == 0) { + if ((StringPtr == NULL) || (AsciiStrLen (StringPtr) == 0)) { StringPtr = "unknown name"; } diff --git a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxMmLib.c b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxMmLib.c index ab2cb7a2b4aa..3b9c30dac267 100644 --- a/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxMmLib.c +++ b/MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxMmLib.c @@ -366,7 +366,9 @@ InternalGetLockBoxQueue ( /** This function find LockBox by GUID. - @param Guid The guid to indentify the LockBox + NULL will be returned by this function if the lock box queue is not found. + + @param Guid The guid to identify the LockBox @return LockBoxData **/ @@ -380,7 +382,11 @@ InternalFindLockBoxByGuid ( LIST_ENTRY *LockBoxQueue; LockBoxQueue = InternalGetLockBoxQueue (); - ASSERT (LockBoxQueue != NULL); + + if (LockBoxQueue == NULL) { + ASSERT (LockBoxQueue != NULL); + return NULL; + } for (Link = LockBoxQueue->ForwardLink; Link != LockBoxQueue; @@ -500,7 +506,11 @@ SaveLockBox ( )); LockBoxQueue = InternalGetLockBoxQueue (); - ASSERT (LockBoxQueue != NULL); + if (LockBoxQueue == NULL) { + ASSERT (LockBoxQueue != NULL); + return EFI_OUT_OF_RESOURCES; + } + InsertTailList (LockBoxQueue, &LockBox->Link); // @@ -834,6 +844,7 @@ RestoreLockBox ( @retval RETURN_SUCCESS the information is restored successfully. @retval RETURN_NOT_STARTED it is too early to invoke this interface @retval RETURN_UNSUPPORTED the service is not supported by implementaion. + @retval RETURN_OUT_OF_RESOURCES noT enough resourceS to save the information. **/ RETURN_STATUS EFIAPI @@ -848,7 +859,10 @@ RestoreAllLockBoxInPlace ( DEBUG ((DEBUG_INFO, "SmmLockBoxSmmLib RestoreAllLockBoxInPlace - Enter\n")); LockBoxQueue = InternalGetLockBoxQueue (); - ASSERT (LockBoxQueue != NULL); + if (LockBoxQueue == NULL) { + ASSERT (LockBoxQueue != NULL); + return EFI_OUT_OF_RESOURCES; + } // // Restore all, Buffer and Length MUST be NULL diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c index 8d62b0c55835..292ada24d121 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c @@ -214,10 +214,12 @@ BmAdjustFvFilePath ( (VOID **)&LoadedImage ); NewDevicePath = AppendDevicePathNode (DevicePathFromHandle (LoadedImage->DeviceHandle), FvFileNode); - FullPath = BmAdjustFvFilePath (NewDevicePath); - FreePool (NewDevicePath); - if (FullPath != NULL) { - return FullPath; + if (NewDevicePath != NULL) { + FullPath = BmAdjustFvFilePath (NewDevicePath); + FreePool (NewDevicePath); + if (FullPath != NULL) { + return FullPath; + } } // @@ -239,7 +241,12 @@ BmAdjustFvFilePath ( } NewDevicePath = AppendDevicePathNode (DevicePathFromHandle (FvHandles[Index]), FvFileNode); - FullPath = BmAdjustFvFilePath (NewDevicePath); + if (NewDevicePath == NULL) { + ASSERT (NewDevicePath != NULL); + continue; + } + + FullPath = BmAdjustFvFilePath (NewDevicePath); FreePool (NewDevicePath); if (FullPath != NULL) { break; @@ -622,6 +629,10 @@ BmExpandUsbDevicePath ( ParentDevicePathSize = (UINTN)ShortformNode - (UINTN)FilePath; RemainingDevicePath = NextDevicePathNode (ShortformNode); Handles = BmFindUsbDevice (FilePath, ParentDevicePathSize, &HandleCount); + if (Handles == NULL) { + ASSERT (Handles != NULL); + return NULL; + } for (Index = 0; Index < HandleCount; Index++) { FilePath = AppendDevicePath (DevicePathFromHandle (Handles[Index]), RemainingDevicePath); @@ -709,13 +720,20 @@ BmExpandFileDevicePath ( ) { NextFullPath = AppendDevicePath (DevicePathFromHandle (Handles[Index]), FilePath); + if (NextFullPath == NULL) { + continue; + } + if (GetNext) { + // this is the break/exit condition. Occurs on first if FullPath input parameter was NULL + // or on the next loop after input parameter FullPath matches NextFullPath. + // NextFullPath will not be NULL so outer loop is broken too break; - } else { - GetNext = (BOOLEAN)(CompareMem (NextFullPath, FullPath, GetDevicePathSize (NextFullPath)) == 0); - FreePool (NextFullPath); - NextFullPath = NULL; } + + GetNext = (BOOLEAN)(CompareMem (NextFullPath, FullPath, GetDevicePathSize (NextFullPath)) == 0); + FreePool (NextFullPath); + NextFullPath = NULL; } } @@ -923,6 +941,10 @@ BmExpandPartitionDevicePath ( // partial partition boot option. Second, check whether the instance could be connected. // Instance = GetNextDevicePathInstance (&TempNewDevicePath, &Size); + if (Instance == NULL) { + break; + } + if (BmMatchPartitionDevicePathNode (Instance, (HARDDRIVE_DEVICE_PATH *)FilePath)) { // // Connect the device path instance, the device path point to hard drive media device path node @@ -941,31 +963,33 @@ BmExpandPartitionDevicePath ( // 2. ACPI()/PCI()/ATA()/Partition()/Partition(A2)/EFI/BootX64.EFI // For simplicity, only #1 is returned. // - FullPath = BmGetNextLoadOptionDevicePath (TempDevicePath, NULL); - FreePool (TempDevicePath); - - if (FullPath != NULL) { - // - // Adjust the 'HDDP' instances sequence if the matched one is not first one. - // - if (NeedAdjust) { - BmCachePartitionDevicePath (&CachedDevicePath, Instance); + if (TempDevicePath != NULL) { + FullPath = BmGetNextLoadOptionDevicePath (TempDevicePath, NULL); + FreePool (TempDevicePath); + + if (FullPath != NULL) { // - // Save the matching Device Path so we don't need to do a connect all next time - // Failing to save only impacts performance next time expanding the short-form device path + // Adjust the 'HDDP' instances sequence if the matched one is not first one. // - Status = gRT->SetVariable ( - L"HDDP", - &mBmHardDriveBootVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, - GetDevicePathSize (CachedDevicePath), - CachedDevicePath - ); + if (NeedAdjust) { + BmCachePartitionDevicePath (&CachedDevicePath, Instance); + // + // Save the matching Device Path so we don't need to do a connect all next time + // Failing to save only impacts performance next time expanding the short-form device path + // + Status = gRT->SetVariable ( + L"HDDP", + &mBmHardDriveBootVariableGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE, + GetDevicePathSize (CachedDevicePath), + CachedDevicePath + ); + } + + FreePool (Instance); + FreePool (CachedDevicePath); + return FullPath; } - - FreePool (Instance); - FreePool (CachedDevicePath); - return FullPath; } } } @@ -1010,7 +1034,11 @@ BmExpandPartitionDevicePath ( // Find the matched partition device path // TempDevicePath = AppendDevicePath (BlockIoDevicePath, NextDevicePathNode (FilePath)); - FullPath = BmGetNextLoadOptionDevicePath (TempDevicePath, NULL); + if (TempDevicePath == NULL) { + continue; + } + + FullPath = BmGetNextLoadOptionDevicePath (TempDevicePath, NULL); FreePool (TempDevicePath); if (FullPath != NULL) { @@ -1103,7 +1131,10 @@ BmExpandMediaDevicePath ( if (GetNext) { return NextFullPath; } else { - FreePool (NextFullPath); + if (NextFullPath != NULL) { + FreePool (NextFullPath); + } + return NULL; } } @@ -1160,7 +1191,11 @@ BmExpandMediaDevicePath ( // Get the device path size of SimpleFileSystem handle // TempDevicePath = DevicePathFromHandle (SimpleFileSystemHandles[Index]); - TempSize = GetDevicePathSize (TempDevicePath) - END_DEVICE_PATH_LENGTH; + if (TempDevicePath == NULL) { + continue; + } + + TempSize = GetDevicePathSize (TempDevicePath) - END_DEVICE_PATH_LENGTH; // // Check whether the device path of boot option is part of the SimpleFileSystem handle's device path // @@ -1169,9 +1204,11 @@ BmExpandMediaDevicePath ( if (GetNext) { break; } else { - GetNext = (BOOLEAN)(CompareMem (NextFullPath, FullPath, GetDevicePathSize (NextFullPath)) == 0); - FreePool (NextFullPath); - NextFullPath = NULL; + if (NextFullPath != NULL) { + GetNext = (BOOLEAN)(CompareMem (NextFullPath, FullPath, GetDevicePathSize (NextFullPath)) == 0); + FreePool (NextFullPath); + NextFullPath = NULL; + } } } } @@ -2256,12 +2293,20 @@ BmEnumerateBootOptions ( } Description = BmGetBootDescription (Handles[Index]); + if (Description == NULL) { + continue; + } + BootOptions = ReallocatePool ( sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCount), sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCount + 1), BootOptions ); - ASSERT (BootOptions != NULL); + if (BootOptions == NULL) { + ASSERT (BootOptions != NULL); + FreePool (Description); + continue; + } Status = EfiBootManagerInitializeLoadOption ( &BootOptions[(*BootOptionCount)++], @@ -2307,12 +2352,20 @@ BmEnumerateBootOptions ( } Description = BmGetBootDescription (Handles[Index]); + if (Description == NULL) { + continue; + } + BootOptions = ReallocatePool ( sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCount), sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCount + 1), BootOptions ); - ASSERT (BootOptions != NULL); + if (BootOptions == NULL) { + ASSERT (BootOptions != NULL); + FreePool (Description); + continue; + } Status = EfiBootManagerInitializeLoadOption ( &BootOptions[(*BootOptionCount)++], @@ -2351,12 +2404,20 @@ BmEnumerateBootOptions ( } Description = BmGetBootDescription (Handles[Index]); + if (Description == NULL) { + continue; + } + BootOptions = ReallocatePool ( sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCount), sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (*BootOptionCount + 1), BootOptions ); - ASSERT (BootOptions != NULL); + if (BootOptions == NULL) { + ASSERT (BootOptions != NULL); + FreePool (Description); + continue; + } Status = EfiBootManagerInitializeLoadOption ( &BootOptions[(*BootOptionCount)++], @@ -2443,6 +2504,9 @@ EfiBootManagerRefreshAllBootOption ( } NvBootOptions = EfiBootManagerGetLoadOptions (&NvBootOptionCount, LoadOptionTypeBoot); + if (NvBootOptions == NULL) { + goto Exit; + } // // Remove invalid EFI boot options from NV @@ -2479,8 +2543,14 @@ EfiBootManagerRefreshAllBootOption ( } } - EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount); - EfiBootManagerFreeLoadOptions (NvBootOptions, NvBootOptionCount); +Exit: + if (BootOptions != NULL) { + EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount); + } + + if (NvBootOptions != NULL) { + EfiBootManagerFreeLoadOptions (NvBootOptions, NvBootOptionCount); + } } /** @@ -2579,14 +2649,17 @@ BmRegisterBootManagerMenu ( FreePool (Description); } - DEBUG_CODE ( - EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions; - UINTN BootOptionCount; + DEBUG_CODE_BEGIN (); + EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions; + UINTN BootOptionCount; - BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot); + BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot); + if (BootOptions != NULL) { ASSERT (EfiBootManagerFindLoadOption (BootOption, BootOptions, BootOptionCount) == -1); EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount); - ); + } + + DEBUG_CODE_END (); return EfiBootManagerAddLoadOptionVariable (BootOption, (UINTN)-1); } @@ -2615,6 +2688,11 @@ EfiBootManagerGetBootManagerMenu ( UINTN Index; BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot); + if ((BootOptions == NULL) || (BootOptionCount == 0)) { + BootOptionCount = 0; + Index = 0; + goto Register; + } for (Index = 0; Index < BootOptionCount; Index++) { if (BmIsBootManagerMenuFilePath (BootOptions[Index].FilePath)) { @@ -2638,6 +2716,7 @@ EfiBootManagerGetBootManagerMenu ( // // Automatically create the Boot#### for Boot Manager Menu when not found. // +Register: if (Index == BootOptionCount) { return BmRegisterBootManagerMenu (BootOption); } else { diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c b/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c index 030b2ee3ec25..5e2982b3330f 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c @@ -175,7 +175,11 @@ BmGetDescriptionFromDiskInfo ( ); if (!EFI_ERROR (Status)) { Description = AllocateZeroPool ((ModelNameLength + SerialNumberLength + 2) * sizeof (CHAR16)); - ASSERT (Description != NULL); + if (Description == NULL) { + ASSERT (Description != NULL); + return NULL; + } + for (Index = 0; Index + 1 < ModelNameLength; Index += 2) { Description[Index] = (CHAR16)IdentifyData.ModelName[Index + 1]; Description[Index + 1] = (CHAR16)IdentifyData.ModelName[Index]; @@ -206,7 +210,10 @@ BmGetDescriptionFromDiskInfo ( ); if (!EFI_ERROR (Status)) { Description = AllocateZeroPool ((VENDOR_IDENTIFICATION_LENGTH + PRODUCT_IDENTIFICATION_LENGTH + 2) * sizeof (CHAR16)); - ASSERT (Description != NULL); + if (Description == NULL) { + ASSERT (Description != NULL); + return NULL; + } // // Per SCSI spec, EFI_SCSI_INQUIRY_DATA.Reserved_5_95[3 - 10] save the Verdor identification @@ -336,7 +343,11 @@ BmGetUsbDescription ( DescMaxSize = StrSize (Manufacturer) + StrSize (Product) + StrSize (SerialNumber); Description = AllocateZeroPool (DescMaxSize); - ASSERT (Description != NULL); + if (Description == NULL) { + ASSERT (Description != NULL); + return NULL; + } + StrCatS (Description, DescMaxSize/sizeof (CHAR16), Manufacturer); StrCatS (Description, DescMaxSize/sizeof (CHAR16), L" "); @@ -367,7 +378,7 @@ BmGetUsbDescription ( @param Handle Controller handle. - @return The description string. + @return The description string or NULL if the string could not be created. **/ CHAR16 * BmGetNetworkDescription ( @@ -499,7 +510,11 @@ BmGetNetworkDescription ( // DescriptionSize = sizeof (L"HTTPv6 (MAC:112233445566 VLAN65535)"); Description = AllocatePool (DescriptionSize); - ASSERT (Description != NULL); + if (Description == NULL) { + ASSERT (Description != NULL); + return NULL; + } + UnicodeSPrint ( Description, DescriptionSize, @@ -792,7 +807,7 @@ BM_GET_BOOT_DESCRIPTION mBmBootDescriptionHandlers[] = { @param Handle Controller handle. - @return The description string. + @return The description string or NULL if the string could not be created. **/ CHAR16 * BmGetBootDescription ( @@ -818,7 +833,11 @@ BmGetBootDescription ( // ONLY for core provided boot description handler. // Temp = AllocatePool (StrSize (DefaultDescription) + sizeof (mBmUefiPrefix)); - ASSERT (Temp != NULL); + if (Temp == NULL) { + ASSERT (Temp != NULL); + return NULL; + } + StrCpyS (Temp, (StrSize (DefaultDescription) + sizeof (mBmUefiPrefix)) / sizeof (CHAR16), mBmUefiPrefix); StrCatS (Temp, (StrSize (DefaultDescription) + sizeof (mBmUefiPrefix)) / sizeof (CHAR16), DefaultDescription); FreePool (DefaultDescription); @@ -882,7 +901,10 @@ BmMakeBootOptionDescriptionUnique ( } Visited = AllocateZeroPool (sizeof (BOOLEAN) * BootOptionCount); - ASSERT (Visited != NULL); + if (Visited == NULL) { + ASSERT (Visited != NULL); + return; + } for (Base = 0; Base < BootOptionCount; Base++) { if (!Visited[Base]) { diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c b/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c index 60e7b1099afe..56af9fc78906 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmConsole.c @@ -193,7 +193,9 @@ EfiBootManagerGetGopDevicePath ( // TempDevicePath = GopPool; GopPool = AppendDevicePathInstance (GopPool, DevicePath); - gBS->FreePool (TempDevicePath); + if (TempDevicePath != NULL) { + gBS->FreePool (TempDevicePath); + } } } @@ -204,9 +206,14 @@ EfiBootManagerGetGopDevicePath ( DEBUG ((DEBUG_INFO, "[Bds] Looking for GOP child deeper ... \n")); TempDevicePath = GopPool; ReturnDevicePath = EfiBootManagerGetGopDevicePath (OpenInfoBuffer[Index].ControllerHandle); - GopPool = AppendDevicePathInstance (GopPool, ReturnDevicePath); - gBS->FreePool (ReturnDevicePath); - gBS->FreePool (TempDevicePath); + if (ReturnDevicePath != NULL) { + GopPool = AppendDevicePathInstance (GopPool, ReturnDevicePath); + gBS->FreePool (ReturnDevicePath); + } + + if (TempDevicePath != NULL) { + gBS->FreePool (TempDevicePath); + } } } } @@ -426,6 +433,8 @@ EfiBootManagerUpdateConsoleVariable ( EFI_DEVICE_PATH_PROTOCOL *NewDevicePath; EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath; + Status = EFI_SUCCESS; + if (ConsoleType >= ARRAY_SIZE (mConVarName)) { return EFI_INVALID_PARAMETER; } @@ -438,6 +447,8 @@ EfiBootManagerUpdateConsoleVariable ( return EFI_UNSUPPORTED; } + TempNewDevicePath = NULL; + // // Delete the ExclusiveDevicePath from current default console // @@ -464,29 +475,34 @@ EfiBootManagerUpdateConsoleVariable ( // Check if there is part of CustomizedConDevicePath in NewDevicePath, delete it. // NewDevicePath = BmDelPartMatchInstance (NewDevicePath, CustomizedConDevicePath); - // - // In the first check, the default console variable will be _ModuleEntryPoint, - // just append current customized device path - // - TempNewDevicePath = NewDevicePath; - NewDevicePath = AppendDevicePathInstance (NewDevicePath, CustomizedConDevicePath); + if (NewDevicePath != NULL) { + // + // In the first check, the default console variable will be _ModuleEntryPoint, + // just append current customized device path + // + TempNewDevicePath = NewDevicePath; + } + + NewDevicePath = AppendDevicePathInstance (NewDevicePath, CustomizedConDevicePath); if (TempNewDevicePath != NULL) { FreePool (TempNewDevicePath); } } } - // - // Finally, Update the variable of the default console by NewDevicePath - // - Status = gRT->SetVariable ( - mConVarName[ConsoleType], - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS - | ((ConsoleType < ConInDev) ? EFI_VARIABLE_NON_VOLATILE : 0), - GetDevicePathSize (NewDevicePath), - NewDevicePath - ); + if (NewDevicePath != NULL) { + // + // Finally, Update the variable of the default console by NewDevicePath + // + Status = gRT->SetVariable ( + mConVarName[ConsoleType], + &gEfiGlobalVariableGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS + | ((ConsoleType < ConInDev) ? EFI_VARIABLE_NON_VOLATILE : 0), + GetDevicePathSize (NewDevicePath), + NewDevicePath + ); + } if (VarConsole == NewDevicePath) { if (VarConsole != NULL) { diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c b/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c index 46a8b780e337..42c66a462ce5 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmDriverHealth.c @@ -84,24 +84,25 @@ BmGetControllerName ( FreePool (LanguageVariable); } - Status = ComponentName->GetControllerName ( - ComponentName, - ControllerHandle, - ChildHandle, - BestLanguage, - &ControllerName - ); + if (BestLanguage != NULL) { + Status = ComponentName->GetControllerName ( + ComponentName, + ControllerHandle, + ChildHandle, + BestLanguage, + &ControllerName + ); + if (!EFI_ERROR (Status)) { + return AllocateCopyPool (StrSize (ControllerName), ControllerName); + } + } } - if (!EFI_ERROR (Status)) { - return AllocateCopyPool (StrSize (ControllerName), ControllerName); - } else { - return ConvertDevicePathToText ( - DevicePathFromHandle (ChildHandle != NULL ? ChildHandle : ControllerHandle), - FALSE, - FALSE - ); - } + return ConvertDevicePathToText ( + DevicePathFromHandle (ChildHandle != NULL ? ChildHandle : ControllerHandle), + FALSE, + FALSE + ); } /** @@ -129,6 +130,9 @@ BmDisplayMessages ( DriverHealthInfo->ControllerHandle, DriverHealthInfo->ChildHandle ); + if (ControllerName == NULL) { + return; + } DEBUG ((DEBUG_INFO, "Controller: %s\n", ControllerName)); Print (L"Controller: %s\n", ControllerName); @@ -465,33 +469,35 @@ BmRepairAllControllers ( // Deal with Repair Required // DriverHealthInfo = EfiBootManagerGetDriverHealthInfo (&Count); - for (Index = 0; Index < Count; Index++) { - if (DriverHealthInfo[Index].HealthStatus == EfiDriverHealthStatusConfigurationRequired) { - ConfigurationRequired = TRUE; - } + if (DriverHealthInfo != NULL) { + for (Index = 0; Index < Count; Index++) { + if (DriverHealthInfo[Index].HealthStatus == EfiDriverHealthStatusConfigurationRequired) { + ConfigurationRequired = TRUE; + } - if (DriverHealthInfo[Index].HealthStatus == EfiDriverHealthStatusRepairRequired) { - RepairRequired = TRUE; + if (DriverHealthInfo[Index].HealthStatus == EfiDriverHealthStatusRepairRequired) { + RepairRequired = TRUE; - BmDisplayMessages (&DriverHealthInfo[Index]); + BmDisplayMessages (&DriverHealthInfo[Index]); - Status = DriverHealthInfo[Index].DriverHealth->Repair ( - DriverHealthInfo[Index].DriverHealth, - DriverHealthInfo[Index].ControllerHandle, - DriverHealthInfo[Index].ChildHandle, - BmRepairNotify - ); - if (!EFI_ERROR (Status) && !ConfigurationRequired) { - Status = DriverHealthInfo[Index].DriverHealth->GetHealthStatus ( + Status = DriverHealthInfo[Index].DriverHealth->Repair ( DriverHealthInfo[Index].DriverHealth, DriverHealthInfo[Index].ControllerHandle, DriverHealthInfo[Index].ChildHandle, - &HealthStatus, - NULL, - NULL + BmRepairNotify ); - if (!EFI_ERROR (Status) && (HealthStatus == EfiDriverHealthStatusConfigurationRequired)) { - ConfigurationRequired = TRUE; + if (!EFI_ERROR (Status) && !ConfigurationRequired) { + Status = DriverHealthInfo[Index].DriverHealth->GetHealthStatus ( + DriverHealthInfo[Index].DriverHealth, + DriverHealthInfo[Index].ControllerHandle, + DriverHealthInfo[Index].ChildHandle, + &HealthStatus, + NULL, + NULL + ); + if (!EFI_ERROR (Status) && (HealthStatus == EfiDriverHealthStatusConfigurationRequired)) { + ConfigurationRequired = TRUE; + } } } } @@ -519,59 +525,67 @@ BmRepairAllControllers ( } } - EfiBootManagerFreeDriverHealthInfo (DriverHealthInfo, Count); + if (DriverHealthInfo != NULL) { + EfiBootManagerFreeDriverHealthInfo (DriverHealthInfo, Count); + } + RepairCount++; } while ((RepairRequired || ConfigurationRequired) && ((MaxRepairCount == 0) || (RepairCount < MaxRepairCount))); RebootRequired = FALSE; ReconnectRequired = FALSE; DriverHealthInfo = EfiBootManagerGetDriverHealthInfo (&Count); - for (Index = 0; Index < Count; Index++) { - BmDisplayMessages (&DriverHealthInfo[Index]); + if (DriverHealthInfo != NULL) { + for (Index = 0; Index < Count; Index++) { + BmDisplayMessages (&DriverHealthInfo[Index]); - if (DriverHealthInfo[Index].HealthStatus == EfiDriverHealthStatusReconnectRequired) { - Status = gBS->DisconnectController (DriverHealthInfo[Index].ControllerHandle, NULL, NULL); - if (EFI_ERROR (Status)) { - // - // Disconnect failed. Need to promote reconnect to a reboot. - // + if (DriverHealthInfo[Index].HealthStatus == EfiDriverHealthStatusReconnectRequired) { + Status = gBS->DisconnectController (DriverHealthInfo[Index].ControllerHandle, NULL, NULL); + if (EFI_ERROR (Status)) { + // + // Disconnect failed. Need to promote reconnect to a reboot. + // + RebootRequired = TRUE; + } else { + gBS->ConnectController (DriverHealthInfo[Index].ControllerHandle, NULL, NULL, TRUE); + ReconnectRequired = TRUE; + } + } + + if (DriverHealthInfo[Index].HealthStatus == EfiDriverHealthStatusRebootRequired) { RebootRequired = TRUE; - } else { - gBS->ConnectController (DriverHealthInfo[Index].ControllerHandle, NULL, NULL, TRUE); - ReconnectRequired = TRUE; } } - if (DriverHealthInfo[Index].HealthStatus == EfiDriverHealthStatusRebootRequired) { - RebootRequired = TRUE; - } + EfiBootManagerFreeDriverHealthInfo (DriverHealthInfo, Count); } - EfiBootManagerFreeDriverHealthInfo (DriverHealthInfo, Count); - DEBUG_CODE_BEGIN (); CHAR16 *ControllerName; DriverHealthInfo = EfiBootManagerGetDriverHealthInfo (&Count); - for (Index = 0; Index < Count; Index++) { - ControllerName = BmGetControllerName ( - DriverHealthInfo[Index].DriverHealthHandle, - DriverHealthInfo[Index].ControllerHandle, - DriverHealthInfo[Index].ChildHandle - ); - DEBUG (( - DEBUG_INFO, - "%02d: %s - %s\n", - Index, - ControllerName, - mBmHealthStatusText[DriverHealthInfo[Index].HealthStatus] - )); - if (ControllerName != NULL) { - FreePool (ControllerName); + if (DriverHealthInfo != NULL) { + for (Index = 0; Index < Count; Index++) { + ControllerName = BmGetControllerName ( + DriverHealthInfo[Index].DriverHealthHandle, + DriverHealthInfo[Index].ControllerHandle, + DriverHealthInfo[Index].ChildHandle + ); + DEBUG (( + DEBUG_INFO, + "%02d: %s - %s\n", + Index, + ControllerName, + mBmHealthStatusText[DriverHealthInfo[Index].HealthStatus] + )); + if (ControllerName != NULL) { + FreePool (ControllerName); + } } + + EfiBootManagerFreeDriverHealthInfo (DriverHealthInfo, Count); } - EfiBootManagerFreeDriverHealthInfo (DriverHealthInfo, Count); DEBUG_CODE_END (); if (ReconnectRequired) { diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c index 90bee73a233e..60b2555dbcf0 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmHotkey.c @@ -689,7 +689,16 @@ BmProcessKeyOption ( for (Index = 0; Index < KeyShiftStateCount; Index++) { Hotkey = AllocateZeroPool (sizeof (BM_HOTKEY)); - ASSERT (Hotkey != NULL); + if (Hotkey == NULL) { + ASSERT (Hotkey != NULL); + if (Handles != NULL) { + FreePool (Handles); + } + + EfiReleaseLock (&mBmHotkeyLock); + + return EFI_OUT_OF_RESOURCES; + } Hotkey->Signature = BM_HOTKEY_SIGNATURE; Hotkey->BootOption = KeyOption->BootOption; @@ -918,11 +927,13 @@ EfiBootManagerStartHotkeyService ( } KeyOptions = BmGetKeyOptions (&KeyOptionCount); - for (Index = 0; Index < KeyOptionCount; Index++) { - BmProcessKeyOption (&KeyOptions[Index]); - } + if (KeyOptions != NULL) { + for (Index = 0; Index < KeyOptionCount; Index++) { + BmProcessKeyOption (&KeyOptions[Index]); + } - BmFreeKeyOptions (KeyOptions, KeyOptionCount); + BmFreeKeyOptions (KeyOptions, KeyOptionCount); + } if (mBmContinueKeyOption != NULL) { BmProcessKeyOption (mBmContinueKeyOption); @@ -1014,27 +1025,31 @@ EfiBootManagerAddKeyOptionVariable ( return Status; } + Index = 0; + KeyOptionCount = 0; KeyOptionNumber = LoadOptionNumberUnassigned; // // Check if the hot key sequence was defined already // KeyOptions = BmGetKeyOptions (&KeyOptionCount); - for (Index = 0; Index < KeyOptionCount; Index++) { - if ((KeyOptions[Index].KeyData.PackedValue == KeyOption.KeyData.PackedValue) && - (CompareMem (KeyOptions[Index].Keys, KeyOption.Keys, KeyOption.KeyData.Options.InputKeyCount * sizeof (EFI_INPUT_KEY)) == 0)) - { - break; - } + if (KeyOptions != NULL) { + for ( ; Index < KeyOptionCount; Index++) { + if ((KeyOptions[Index].KeyData.PackedValue == KeyOption.KeyData.PackedValue) && + (CompareMem (KeyOptions[Index].Keys, KeyOption.Keys, KeyOption.KeyData.Options.InputKeyCount * sizeof (EFI_INPUT_KEY)) == 0)) + { + break; + } - if ((KeyOptionNumber == LoadOptionNumberUnassigned) && - (KeyOptions[Index].OptionNumber > Index) - ) - { - KeyOptionNumber = Index; + if ((KeyOptionNumber == LoadOptionNumberUnassigned) && + (KeyOptions[Index].OptionNumber > Index) + ) + { + KeyOptionNumber = Index; + } } - } - BmFreeKeyOptions (KeyOptions, KeyOptionCount); + BmFreeKeyOptions (KeyOptions, KeyOptionCount); + } if (Index < KeyOptionCount) { return EFI_ALREADY_STARTED; @@ -1155,35 +1170,37 @@ EfiBootManagerDeleteKeyOptionVariable ( // Status = EFI_NOT_FOUND; KeyOptions = BmGetKeyOptions (&KeyOptionCount); - for (Index = 0; Index < KeyOptionCount; Index++) { - if ((KeyOptions[Index].KeyData.PackedValue == KeyOption.KeyData.PackedValue) && - (CompareMem ( - KeyOptions[Index].Keys, - KeyOption.Keys, - KeyOption.KeyData.Options.InputKeyCount * sizeof (EFI_INPUT_KEY) - ) == 0) - ) - { - UnicodeSPrint (KeyOptionName, sizeof (KeyOptionName), L"Key%04x", KeyOptions[Index].OptionNumber); - Status = gRT->SetVariable ( - KeyOptionName, - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, - 0, - NULL - ); - // - // Return the deleted key option in case needed by caller - // - if (DeletedOption != NULL) { - CopyMem (DeletedOption, &KeyOptions[Index], sizeof (EFI_BOOT_MANAGER_KEY_OPTION)); - } + if (KeyOptions != NULL) { + for (Index = 0; Index < KeyOptionCount; Index++) { + if ((KeyOptions[Index].KeyData.PackedValue == KeyOption.KeyData.PackedValue) && + (CompareMem ( + KeyOptions[Index].Keys, + KeyOption.Keys, + KeyOption.KeyData.Options.InputKeyCount * sizeof (EFI_INPUT_KEY) + ) == 0) + ) + { + UnicodeSPrint (KeyOptionName, sizeof (KeyOptionName), L"Key%04x", KeyOptions[Index].OptionNumber); + Status = gRT->SetVariable ( + KeyOptionName, + &gEfiGlobalVariableGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE, + 0, + NULL + ); + // + // Return the deleted key option in case needed by caller + // + if (DeletedOption != NULL) { + CopyMem (DeletedOption, &KeyOptions[Index], sizeof (EFI_BOOT_MANAGER_KEY_OPTION)); + } - break; + break; + } } - } - BmFreeKeyOptions (KeyOptions, KeyOptionCount); + BmFreeKeyOptions (KeyOptions, KeyOptionCount); + } EfiReleaseLock (&mBmHotkeyLock); diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c index 83a2f893e41a..72d27a2df8e8 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmLoadOption.c @@ -47,7 +47,11 @@ BmForEachVariable ( NameSize = sizeof (CHAR16); Name = AllocateZeroPool (NameSize); - ASSERT (Name != NULL); + if (Name == NULL) { + ASSERT (Name != NULL); + return; + } + while (TRUE) { NewNameSize = NameSize; Status = gRT->GetNextVariableName (&NewNameSize, Name, &Guid); @@ -220,7 +224,10 @@ structure. + Option->OptionalDataSize; Variable = AllocatePool (VariableSize); - ASSERT (Variable != NULL); + if (Variable == NULL) { + ASSERT (Variable != NULL); + return EFI_OUT_OF_RESOURCES; + } Ptr = Variable; WriteUnaligned32 ((UINT32 *)Ptr, Option->Attributes); @@ -282,6 +289,8 @@ structure. @param Position Position of the new load option to put in the ****Order variable. @retval EFI_SUCCESS The boot#### or driver#### have been successfully registered. + @retval EFI_NOT_FOUND The boot option order variable could not be found. + @retval EFI_OUT_OF_RESOURCES Insufficient memory resources to allocate a memory buffer. @retval EFI_ALREADY_STARTED The option number of Option is being used already. @retval EFI_STATUS Return the status of gRT->SetVariable (). @@ -317,7 +326,12 @@ BmAddOptionNumberToOrderVariable ( Position = MIN (Position, OptionOrderSize / sizeof (UINT16)); NewOptionOrder = AllocatePool (OptionOrderSize + sizeof (UINT16)); - ASSERT (NewOptionOrder != NULL); + if (NewOptionOrder == NULL) { + ASSERT (NewOptionOrder != NULL); + Status = EFI_OUT_OF_RESOURCES; + goto Exit; + } + if (OptionOrderSize != 0) { CopyMem (NewOptionOrder, OptionOrder, Position * sizeof (UINT16)); CopyMem (&NewOptionOrder[Position + 1], &OptionOrder[Position], OptionOrderSize - Position * sizeof (UINT16)); @@ -335,6 +349,7 @@ BmAddOptionNumberToOrderVariable ( FreePool (NewOptionOrder); } +Exit: if (OptionOrder != NULL) { FreePool (OptionOrder); } @@ -438,6 +453,9 @@ EfiBootManagerSortLoadOptionVariable ( UINT16 *OptionOrder; LoadOption = EfiBootManagerGetLoadOptions (&LoadOptionCount, OptionType); + if (LoadOption == NULL) { + return; + } // // Insertion sort algorithm @@ -453,7 +471,11 @@ EfiBootManagerSortLoadOptionVariable ( // Create new ****Order variable // OptionOrder = AllocatePool (LoadOptionCount * sizeof (UINT16)); - ASSERT (OptionOrder != NULL); + if (OptionOrder == NULL) { + ASSERT (OptionOrder != NULL); + return; + } + for (Index = 0; Index < LoadOptionCount; Index++) { OptionOrder[Index] = (UINT16)LoadOption[Index].OptionNumber; } @@ -1105,7 +1127,10 @@ EfiBootManagerGetLoadOptions ( *OptionCount = OptionOrderSize / sizeof (UINT16); Options = AllocatePool (*OptionCount * sizeof (EFI_BOOT_MANAGER_LOAD_OPTION)); - ASSERT (Options != NULL); + if (Options == NULL) { + ASSERT (Options != NULL); + return NULL; + } OptionIndex = 0; for (Index = 0; Index < *OptionCount; Index++) { @@ -1128,7 +1153,11 @@ EfiBootManagerGetLoadOptions ( if (OptionIndex < *OptionCount) { Options = ReallocatePool (*OptionCount * sizeof (EFI_BOOT_MANAGER_LOAD_OPTION), OptionIndex * sizeof (EFI_BOOT_MANAGER_LOAD_OPTION), Options); - ASSERT (Options != NULL); + if (Options == NULL) { + ASSERT (Options != NULL); + return NULL; + } + *OptionCount = OptionIndex; } } else if (LoadOptionType == LoadOptionTypePlatformRecovery) { diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c index a5e32ebdbab6..1ffcd467d799 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c @@ -57,7 +57,10 @@ BmDelPartMatchInstance ( } } - FreePool (Instance); + if (Instance != NULL) { + FreePool (Instance); + } + Instance = GetNextDevicePathInstance (&Multi, &InstanceSize); InstanceSize -= END_DEVICE_PATH_LENGTH; } diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c index 63a37ab59ae4..65bcdf381d31 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c @@ -8,6 +8,8 @@ #include "InternalHiiLib.h" +#include + #define GUID_CONFIG_STRING_TYPE 0x00 #define NAME_CONFIG_STRING_TYPE 0x01 #define PATH_CONFIG_STRING_TYPE 0x02 @@ -51,10 +53,11 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_PACKAGE_HEADER mEndOfPakageList = { If HiiHandle could not be found in the HII database, then ASSERT. If Guid is NULL, then ASSERT. - @param Handle Hii handle - @param Guid Package list GUID + @param Handle Hii handle + @param Guid Package list GUID - @retval EFI_SUCCESS Successfully extract GUID from Hii database. + @retval EFI_SUCCESS Successfully extract GUID from Hii database. + @retval EFI_OUT_OF_RESOURCES Insufficient memory resources to perform a necessary memory allocation. **/ EFI_STATUS @@ -68,8 +71,11 @@ InternalHiiExtractGuidFromHiiHandle ( UINTN BufferSize; EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; - ASSERT (Guid != NULL); - ASSERT (Handle != NULL); + if ((Handle == NULL) || (Guid == NULL)) { + ASSERT (Guid != NULL); + ASSERT (Handle != NULL); + return EFI_INVALID_PARAMETER; + } // // Get HII PackageList @@ -82,7 +88,10 @@ InternalHiiExtractGuidFromHiiHandle ( if (Status == EFI_BUFFER_TOO_SMALL) { HiiPackageList = AllocatePool (BufferSize); - ASSERT (HiiPackageList != NULL); + if (HiiPackageList == NULL) { + ASSERT (HiiPackageList != NULL); + return EFI_OUT_OF_RESOURCES; + } Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &BufferSize, HiiPackageList); } @@ -1209,7 +1218,7 @@ ValidateQuestionFromVfr ( // Check IFR value is in block data, then Validate Value // PackageOffset = sizeof (EFI_HII_PACKAGE_LIST_HEADER); - while (PackageOffset < PackageListLength) { + while ((UINTN)PackageOffset < PackageListLength) { CopyMem (&PackageHeader, (UINT8 *)HiiPackageList + PackageOffset, sizeof (PackageHeader)); // @@ -1359,7 +1368,10 @@ ValidateQuestionFromVfr ( if (NameValueType) { QuestionName = HiiGetString (HiiHandle, IfrOneOf->Question.VarStoreInfo.VarName, NULL); - ASSERT (QuestionName != NULL); + if (QuestionName == NULL) { + ASSERT (QuestionName != NULL); + return EFI_INVALID_PARAMETER; + } if (StrStr (RequestElement, QuestionName) == NULL) { // @@ -1455,7 +1467,10 @@ ValidateQuestionFromVfr ( if (NameValueType) { QuestionName = HiiGetString (HiiHandle, IfrNumeric->Question.VarStoreInfo.VarName, NULL); - ASSERT (QuestionName != NULL); + if (QuestionName == NULL) { + ASSERT (QuestionName != NULL); + return EFI_INVALID_PARAMETER; + } if (StrStr (RequestElement, QuestionName) == NULL) { // @@ -1647,7 +1662,10 @@ ValidateQuestionFromVfr ( if (NameValueType) { QuestionName = HiiGetString (HiiHandle, IfrCheckBox->Question.VarStoreInfo.VarName, NULL); - ASSERT (QuestionName != NULL); + if (QuestionName == NULL) { + ASSERT (QuestionName != NULL); + return EFI_INVALID_PARAMETER; + } if (StrStr (RequestElement, QuestionName) == NULL) { // @@ -1749,7 +1767,10 @@ ValidateQuestionFromVfr ( Width = (UINT16)(IfrString->MaxSize * sizeof (UINT16)); if (NameValueType) { QuestionName = HiiGetString (HiiHandle, IfrString->Question.VarStoreInfo.VarName, NULL); - ASSERT (QuestionName != NULL); + if (QuestionName == NULL) { + ASSERT (QuestionName != NULL); + return EFI_INVALID_PARAMETER; + } StringPtr = StrStr (RequestElement, QuestionName); if (StringPtr == NULL) { @@ -1929,6 +1950,8 @@ GetBlockDataInfo ( IFR_BLOCK_DATA *BlockArray; UINT8 *DataBuffer; + UINT16 Sum1, Sum2; + // // Initialize the local variables. // @@ -1952,10 +1975,14 @@ GetBlockDataInfo ( goto Done; } - InitializeListHead (&BlockArray->Entry); - StringPtr = StrStr (ConfigElement, L"&OFFSET="); - ASSERT (StringPtr != NULL); + if (StringPtr == NULL) { + ASSERT (StringPtr != NULL); + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + + InitializeListHead (&BlockArray->Entry); // // Parse each if exists @@ -2120,14 +2147,20 @@ GetBlockDataInfo ( while ((Link != &BlockArray->Entry) && (Link->ForwardLink != &BlockArray->Entry)) { BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry); NewBlockData = BASE_CR (Link->ForwardLink, IFR_BLOCK_DATA, Entry); - if ((NewBlockData->Offset >= BlockData->Offset) && (NewBlockData->Offset <= (BlockData->Offset + BlockData->Width))) { - if ((NewBlockData->Offset + NewBlockData->Width) > (BlockData->Offset + BlockData->Width)) { - BlockData->Width = (UINT16)(NewBlockData->Offset + NewBlockData->Width - BlockData->Offset); + if ((!EFI_ERROR (SafeUint16Add (BlockData->Offset, BlockData->Width, &Sum1))) && + (!EFI_ERROR (SafeUint16Add (NewBlockData->Offset, NewBlockData->Width, &Sum2))) && + (NewBlockData->Offset >= BlockData->Offset) && + (NewBlockData->Offset <= Sum1) && + (Sum2 > Sum1)) + { + Sum1 = BlockData->Width; + if (!EFI_ERROR (SafeUint16Sub (Sum2, BlockData->Offset, &BlockData->Width))) { + RemoveEntryList (Link->ForwardLink); + FreePool (NewBlockData); + continue; + } else { + BlockData->Width = Sum1; } - - RemoveEntryList (Link->ForwardLink); - FreePool (NewBlockData); - continue; } Link = Link->ForwardLink; @@ -2210,7 +2243,10 @@ InternalHiiValidateCurrentSetting ( // Skip header part. // StringPtr = StrStr (ConfigResp, L"PATH="); - ASSERT (StringPtr != NULL); + if (StringPtr == NULL) { + ASSERT (StringPtr != NULL); + return EFI_OUT_OF_RESOURCES; + } if (StrStr (StringPtr, L"&") != NULL) { NameValueType = TRUE; @@ -2273,7 +2309,10 @@ GetElementsFromRequest ( EFI_STRING TmpRequest; TmpRequest = StrStr (ConfigRequest, L"PATH="); - ASSERT (TmpRequest != NULL); + if (TmpRequest == NULL) { + ASSERT (TmpRequest != NULL); + return FALSE; + } if ((StrStr (TmpRequest, L"&OFFSET=") != NULL) || (StrStr (TmpRequest, L"&") != NULL)) { return TRUE; @@ -2896,6 +2935,11 @@ HiiGetBrowserData ( Size = (StrLen (mConfigHdrTemplate) + 1) * sizeof (CHAR16); Size = Size + (StrLen (ResultsData) + 1) * sizeof (CHAR16); ConfigResp = AllocateZeroPool (Size); + if (ConfigResp == NULL) { + FreePool (ResultsData); + return FALSE; + } + UnicodeSPrint (ConfigResp, Size, L"%s&%s", mConfigHdrTemplate, ResultsData); // @@ -2976,6 +3020,10 @@ HiiSetBrowserData ( // Size = (StrLen (mConfigHdrTemplate) + 32 + 1) * sizeof (CHAR16); ConfigRequest = AllocateZeroPool (Size); + if (ConfigRequest == NULL) { + return FALSE; + } + UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", mConfigHdrTemplate, (UINT64)BufferSize); } else { // @@ -2985,6 +3033,10 @@ HiiSetBrowserData ( Size = StrLen (mConfigHdrTemplate) * sizeof (CHAR16); Size = Size + (StrLen (RequestElement) + 1) * sizeof (CHAR16); ConfigRequest = AllocateZeroPool (Size); + if (ConfigRequest == NULL) { + return FALSE; + } + UnicodeSPrint (ConfigRequest, Size, L"%s%s", mConfigHdrTemplate, RequestElement); } diff --git a/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf b/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf index d432b439bc01..be0c41757883 100644 --- a/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf +++ b/MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf @@ -41,6 +41,7 @@ UefiLib UefiHiiServicesLib PrintLib + SafeIntLib [Protocols] gEfiFormBrowser2ProtocolGuid ## SOMETIMES_CONSUMES diff --git a/MdeModulePkg/Library/UefiSortLib/UefiSortLib.c b/MdeModulePkg/Library/UefiSortLib/UefiSortLib.c index 0ba12449309a..46a3e8de4f34 100644 --- a/MdeModulePkg/Library/UefiSortLib/UefiSortLib.c +++ b/MdeModulePkg/Library/UefiSortLib/UefiSortLib.c @@ -62,7 +62,10 @@ PerformQuickSort ( ASSERT (CompareFunction != NULL); Buffer = AllocateZeroPool (ElementSize); - ASSERT (Buffer != NULL); + if (Buffer == NULL) { + ASSERT (Buffer != NULL); + return; + } QuickSort ( BufferToSort, diff --git a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiGenFromFv.c b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiGenFromFv.c index 562f5a02f602..544c303aa4b4 100644 --- a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiGenFromFv.c +++ b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiGenFromFv.c @@ -178,6 +178,8 @@ ParseFfs ( UINT8 NumberofMatchingVfrBin; UINTN *VfrBinBaseAddress; + VfrBinBaseAddress = NULL; + Status = Fv2->ReadFile ( Fv2, DriverGuid, diff --git a/MdeModulePkg/Library/VarCheckPcdLib/VarCheckPcdLibNullClass.c b/MdeModulePkg/Library/VarCheckPcdLib/VarCheckPcdLibNullClass.c index 90cef6e85d27..ab9bc5b27146 100644 --- a/MdeModulePkg/Library/VarCheckPcdLib/VarCheckPcdLibNullClass.c +++ b/MdeModulePkg/Library/VarCheckPcdLib/VarCheckPcdLibNullClass.c @@ -429,6 +429,8 @@ LocateVarCheckPcdBin ( VAR_CHECK_PCD_VARIABLE_HEADER *VarCheckPcdBin; UINTN VarCheckPcdBinSize; + VarCheckPcdBin = NULL; + // // Search the VarCheckPcdBin from the first RAW section of current FFS. // diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c index bb258c9710d9..41e7150bd2a4 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c @@ -336,6 +336,11 @@ SdtRegisterNotify ( CurrentNotifyList = AllocatePool (sizeof (EFI_ACPI_NOTIFY_LIST)); ASSERT (CurrentNotifyList != NULL); + if (CurrentNotifyList == NULL) { + DEBUG ((DEBUG_ERROR, "%a Failed to allocate pool\n", __func__)); + return; + } + // // Initialize the table contents // @@ -484,6 +489,11 @@ SdtOpenSdtTable ( AmlHandle = AllocatePool (sizeof (*AmlHandle)); ASSERT (AmlHandle != NULL); + + if (AmlHandle == NULL) { + return EFI_NOT_FOUND; + } + AmlHandle->Signature = EFI_AML_ROOT_HANDLE_SIGNATURE; AmlHandle->Buffer = (VOID *)((UINTN)Table->Table + sizeof (EFI_ACPI_SDT_HEADER)); AmlHandle->Size = Table->Table->Length - sizeof (EFI_ACPI_SDT_HEADER); @@ -561,6 +571,10 @@ SdtOpenEx ( AmlHandle = AllocatePool (sizeof (*AmlHandle)); ASSERT (AmlHandle != NULL); + if (AmlHandle == NULL) { + return EFI_INVALID_PARAMETER; + } + AmlHandle->Signature = EFI_AML_HANDLE_SIGNATURE; AmlHandle->Buffer = Buffer; AmlHandle->AmlByteEncoding = AmlByteEncoding; @@ -928,6 +942,11 @@ SdtDuplicateHandle ( DstAmlHandle = AllocatePool (sizeof (*DstAmlHandle)); ASSERT (DstAmlHandle != NULL); + + if (DstAmlHandle == NULL) { + return NULL; + } + CopyMem (DstAmlHandle, (VOID *)AmlHandle, sizeof (*DstAmlHandle)); return DstAmlHandle; @@ -967,6 +986,11 @@ SdtFindPathFromRoot ( // Duplicate RootHandle // *HandleOut = (EFI_ACPI_HANDLE)SdtDuplicateHandle (AmlHandle); + + if (*HandleOut == NULL) { + return EFI_INVALID_PARAMETER; + } + return EFI_SUCCESS; } diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.c index f50068d0e0fa..2300a96d61e3 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.c +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.c @@ -44,7 +44,12 @@ InitializeAcpiTableDxe ( // Initialize our protocol // PrivateData = AllocateZeroPool (sizeof (EFI_ACPI_TABLE_INSTANCE)); - ASSERT (PrivateData); + + if (PrivateData == NULL) { + ASSERT (PrivateData); + return EFI_OUT_OF_RESOURCES; + } + PrivateData->Signature = EFI_ACPI_TABLE_SIGNATURE; // diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c index f2a7be577855..250beb9b4cb9 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c @@ -539,6 +539,10 @@ AddTableToList ( CurrentTableList = AllocatePool (sizeof (EFI_ACPI_TABLE_LIST)); ASSERT (CurrentTableList); + if (CurrentTableList == NULL) { + return EFI_OUT_OF_RESOURCES; + } + // // Determine table type and size // diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlNamespace.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlNamespace.c index 61c7273048ad..aaa2999d3cac 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlNamespace.c +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlNamespace.c @@ -32,7 +32,7 @@ AmlConstructNodeList ( @param[in] Parent AML parent node list. @param[in] AmlByteEncoding AML Byte Encoding. - @return AML Node. + @return AML Node or NULL if insufficient resources to allocate a buffer **/ EFI_AML_NODE_LIST * AmlCreateNode ( @@ -44,7 +44,11 @@ AmlCreateNode ( EFI_AML_NODE_LIST *AmlNodeList; AmlNodeList = AllocatePool (sizeof (*AmlNodeList)); - ASSERT (AmlNodeList != NULL); + + if (AmlNodeList == NULL) { + ASSERT (AmlNodeList != NULL); + return NULL; + } AmlNodeList->Signature = EFI_AML_NODE_LIST_SIGNATURE; CopyMem (AmlNodeList->Name, NameSeg, AML_NAME_SEG_SIZE); @@ -108,6 +112,11 @@ AmlFindNodeInThis ( // Create new node with NULL buffer - it means namespace not be returned. // AmlNodeList = AmlCreateNode (NameSeg, AmlParentNodeList, NULL); + + if (AmlNodeList == NULL) { + return NULL; + } + InsertTailList (&AmlParentNodeList->Children, &AmlNodeList->Link); return AmlNodeList; @@ -539,6 +548,10 @@ AmlFindPath ( RootNameSeg[1] = 0; AmlRootNodeList = AmlCreateNode (RootNameSeg, NULL, AmlHandle->AmlByteEncoding); + if (AmlRootNodeList == NULL) { + return EFI_OUT_OF_RESOURCES; + } + Status = AmlConstructNodeList ( AmlHandle, AmlRootNodeList, // Root diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlString.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlString.c index 9f6777057847..e341c701d92d 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlString.c +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlString.c @@ -379,7 +379,7 @@ AmlUpperCaseCopyMem ( @param[in] AslPath ASL name. - @return AmlName + @return AmlName or NULL if insufficient resources to allocate a buffer **/ UINT8 * AmlNameFromAslName ( @@ -401,7 +401,11 @@ AmlNameFromAslName ( } AmlPath = AllocatePool (TotalLength); - ASSERT (AmlPath != NULL); + + if (AmlPath == NULL) { + ASSERT (AmlPath != NULL); + return NULL; + } AmlBuffer = AmlPath; Buffer = AslPath; diff --git a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c index 72de8d3211b7..e471b764bb51 100644 --- a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c +++ b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c @@ -897,8 +897,11 @@ BdsEntry ( // Execute Driver Options // LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypeDriver); - ProcessLoadOptions (LoadOptions, LoadOptionCount); - EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount); + + if ((LoadOptionCount != 0) && (LoadOptions != NULL)) { + ProcessLoadOptions (LoadOptions, LoadOptionCount); + EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount); + } // // Connect consoles @@ -969,15 +972,18 @@ BdsEntry ( mBdsLoadOptionName[LoadOptionType] )); LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionType); - for (Index = 0; Index < LoadOptionCount; Index++) { - DEBUG (( - DEBUG_INFO, - " %s%04x: %s \t\t 0x%04x\n", - mBdsLoadOptionName[LoadOptionType], - LoadOptions[Index].OptionNumber, - LoadOptions[Index].Description, - LoadOptions[Index].Attributes - )); + + if ((LoadOptionCount != 0) && (LoadOptions != NULL)) { + for (Index = 0; Index < LoadOptionCount; Index++) { + DEBUG (( + DEBUG_INFO, + " %s%04x: %s \t\t 0x%04x\n", + mBdsLoadOptionName[LoadOptionType], + LoadOptions[Index].OptionNumber, + LoadOptions[Index].Description, + LoadOptions[Index].Attributes + )); + } } EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount); @@ -1033,8 +1039,11 @@ BdsEntry ( // Execute SysPrep#### // LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypeSysPrep); - ProcessLoadOptions (LoadOptions, LoadOptionCount); - EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount); + + if ((LoadOptionCount != 0) && (LoadOptions != NULL)) { + ProcessLoadOptions (LoadOptions, LoadOptionCount); + EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount); + } // // Execute Key#### @@ -1091,8 +1100,10 @@ BdsEntry ( // Retry to boot if any of the boot succeeds // LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypeBoot); - BootSuccess = BootBootOptions (LoadOptions, LoadOptionCount, (BootManagerMenuStatus != EFI_NOT_FOUND) ? &BootManagerMenu : NULL); - EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount); + if ((LoadOptionCount != 0) && (LoadOptions != NULL)) { + BootSuccess = BootBootOptions (LoadOptions, LoadOptionCount, (BootManagerMenuStatus != EFI_NOT_FOUND) ? &BootManagerMenu : NULL); + EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount); + } } while (BootSuccess); } @@ -1103,8 +1114,11 @@ BdsEntry ( if (!BootSuccess) { if (PcdGetBool (PcdPlatformRecoverySupport)) { LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery); - ProcessLoadOptions (LoadOptions, LoadOptionCount); - EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount); + + if ((LoadOptionCount != 0) && (LoadOptions != NULL)) { + ProcessLoadOptions (LoadOptions, LoadOptionCount); + EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount); + } } else if (PlatformDefaultBootOptionValid) { // // When platform recovery is not enabled, still boot to platform default file path. diff --git a/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c b/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c index 8e26a7d7959e..8e69e7a7fb05 100644 --- a/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c +++ b/MdeModulePkg/Universal/CapsulePei/UefiCapsule.c @@ -1277,7 +1277,7 @@ CreateState ( UINTN Size; EFI_PHYSICAL_ADDRESS NewBuffer; UINTN CapsuleNumber; - UINT32 Index; + UINTN Index; EFI_PHYSICAL_ADDRESS BaseAddress; UINT64 Length; diff --git a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c index a7f0225f305b..7d32d9a7345b 100644 --- a/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c +++ b/MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatform.c @@ -1096,10 +1096,8 @@ ConPlatformMatchDevicePaths ( // // If performing Delete operation, the NewDevicePath must not be NULL. // - if (Delete) { - if (NewDevicePath == NULL) { - return EFI_INVALID_PARAMETER; - } + if (Delete && (NewDevicePath == NULL)) { + return EFI_INVALID_PARAMETER; } TempDevicePath1 = NULL; @@ -1178,6 +1176,8 @@ ConPlatformUpdateDeviceVariable ( EFI_DEVICE_PATH_PROTOCOL *VariableDevicePath; EFI_DEVICE_PATH_PROTOCOL *NewVariableDevicePath; + Status = EFI_SUCCESS; + VariableDevicePath = NULL; NewVariableDevicePath = NULL; @@ -1187,7 +1187,7 @@ ConPlatformUpdateDeviceVariable ( // it is the caller's responsibility to free the memory before return. // VariableDevicePath = ConPlatformGetVariable (VariableName); - + // At this point, VariableDevicePath may be null. This is expected. if (Operation != Delete) { // // Match specified DevicePath in Console Variable. diff --git a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c index b895dafedeaa..fa364212320b 100644 --- a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c +++ b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c @@ -283,7 +283,11 @@ InitializeGraphicsConsoleTextMode ( // Reserve 2 modes for 80x25, 80x50 of graphics console. // NewModeBuffer = AllocateZeroPool (sizeof (GRAPHICS_CONSOLE_MODE_DATA) * (Count + 2)); - ASSERT (NewModeBuffer != NULL); + + if (NewModeBuffer == NULL) { + ASSERT (NewModeBuffer != NULL); + return EFI_OUT_OF_RESOURCES; + } // // Mode 0 and mode 1 is for 80x25, 80x50 according to UEFI spec. @@ -463,7 +467,7 @@ GraphicsConsoleControllerDriverStart ( // MaxMode = Private->GraphicsOutput->Mode->MaxMode; - for (ModeIndex = 0; ModeIndex < MaxMode; ModeIndex++) { + for (ModeIndex = 0; (UINTN)ModeIndex < MaxMode; ModeIndex++) { Status = Private->GraphicsOutput->QueryMode ( Private->GraphicsOutput, ModeIndex, @@ -2084,7 +2088,11 @@ RegisterFontPackage ( PackageLength = sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR) + mNarrowFontSize + 4; Package = AllocateZeroPool (PackageLength); - ASSERT (Package != NULL); + + if (Package == NULL) { + ASSERT (Package != NULL); + return; + } WriteUnaligned32 ((UINT32 *)Package, PackageLength); SimplifiedFont = (EFI_HII_SIMPLE_FONT_PACKAGE_HDR *)(Package + 4); diff --git a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c index e2d779c78378..d1c128de6212 100644 --- a/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c +++ b/MdeModulePkg/Universal/Console/TerminalDxe/Terminal.c @@ -1261,19 +1261,21 @@ TerminalRemoveConsoleDevVariable ( FreePool (OriginalVariable); if (FoundOne) { - VariableSize = GetDevicePathSize (NewVariable); - - Status = gRT->SetVariable ( - VariableName, - &gEfiGlobalVariableGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, - VariableSize, - NewVariable - ); - // - // Shrinking variable with existing variable driver implementation shouldn't fail. - // - ASSERT_EFI_ERROR (Status); + if (NewVariable != NULL) { + VariableSize = GetDevicePathSize (NewVariable); + + Status = gRT->SetVariable ( + VariableName, + &gEfiGlobalVariableGuid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, + VariableSize, + NewVariable + ); + // + // Shrinking variable with existing variable driver implementation shouldn't fail. + // + ASSERT_EFI_ERROR (Status); + } } if (NewVariable != NULL) { diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c index 531b3b45ea0f..61d4a6bd9867 100644 --- a/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c +++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c @@ -359,7 +359,7 @@ PartitionInstallMbrChildHandles ( if (ExtMbrStartingLba == 0) { break; } - } while (ExtMbrStartingLba < ParentHdDev.PartitionSize); + } while ((UINT64)ExtMbrStartingLba < ParentHdDev.PartitionSize); } Done: diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c index 2dac121c478c..eccc2abf9e49 100644 --- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c +++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c @@ -479,81 +479,85 @@ UpdateMainForm ( StartOpCodeHandle = HiiAllocateOpCodeHandle (); ASSERT (StartOpCodeHandle != NULL); - EndOpCodeHandle = HiiAllocateOpCodeHandle (); - ASSERT (EndOpCodeHandle != NULL); + if (StartOpCodeHandle != NULL) { + EndOpCodeHandle = HiiAllocateOpCodeHandle (); + ASSERT (EndOpCodeHandle != NULL); + + if (EndOpCodeHandle == NULL) { + // + // Create Hii Extend Label OpCode as the start opcode + // + StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode ( + StartOpCodeHandle, + &gEfiIfrTianoGuid, + NULL, + sizeof (EFI_IFR_GUID_LABEL) + ); + StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + StartLabel->Number = MAIN_LABEL_LIST_START; + + // + // Create Hii Extend Label OpCode as the end opcode + // + EndLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode ( + EndOpCodeHandle, + &gEfiIfrTianoGuid, + NULL, + sizeof (EFI_IFR_GUID_LABEL) + ); + EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; + EndLabel->Number = MAIN_LABEL_LIST_END; + + Index = 0; + BASE_LIST_FOR_EACH (Entry, &RegisteredRamDisks) { + PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry); + PrivateData->CheckBoxId = (EFI_QUESTION_ID) + (MAIN_CHECKBOX_QUESTION_ID_START + Index); + // + // CheckBox is unchecked by default. + // + PrivateData->CheckBoxChecked = FALSE; + String = RamDiskStr; + + UnicodeSPrint ( + String, + sizeof (RamDiskStr), + L" RAM Disk %d: [0x%lx, 0x%lx]\n", + Index, + PrivateData->StartingAddr, + PrivateData->StartingAddr + PrivateData->Size - 1 + ); - // - // Create Hii Extend Label OpCode as the start opcode - // - StartLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode ( - StartOpCodeHandle, - &gEfiIfrTianoGuid, - NULL, - sizeof (EFI_IFR_GUID_LABEL) - ); - StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; - StartLabel->Number = MAIN_LABEL_LIST_START; + StringId = HiiSetString (ConfigPrivate->HiiHandle, 0, RamDiskStr, NULL); + ASSERT (StringId != 0); + + HiiCreateCheckBoxOpCode ( + StartOpCodeHandle, + PrivateData->CheckBoxId, + 0, + 0, + StringId, + STRING_TOKEN (STR_RAM_DISK_LIST_HELP), + EFI_IFR_FLAG_CALLBACK, + 0, + NULL + ); - // - // Create Hii Extend Label OpCode as the end opcode - // - EndLabel = (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode ( - EndOpCodeHandle, - &gEfiIfrTianoGuid, - NULL, - sizeof (EFI_IFR_GUID_LABEL) - ); - EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL; - EndLabel->Number = MAIN_LABEL_LIST_END; - - Index = 0; - BASE_LIST_FOR_EACH (Entry, &RegisteredRamDisks) { - PrivateData = RAM_DISK_PRIVATE_FROM_THIS (Entry); - PrivateData->CheckBoxId = (EFI_QUESTION_ID) - (MAIN_CHECKBOX_QUESTION_ID_START + Index); - // - // CheckBox is unchecked by default. - // - PrivateData->CheckBoxChecked = FALSE; - String = RamDiskStr; - - UnicodeSPrint ( - String, - sizeof (RamDiskStr), - L" RAM Disk %d: [0x%lx, 0x%lx]\n", - Index, - PrivateData->StartingAddr, - PrivateData->StartingAddr + PrivateData->Size - 1 - ); - - StringId = HiiSetString (ConfigPrivate->HiiHandle, 0, RamDiskStr, NULL); - ASSERT (StringId != 0); - - HiiCreateCheckBoxOpCode ( - StartOpCodeHandle, - PrivateData->CheckBoxId, - 0, - 0, - StringId, - STRING_TOKEN (STR_RAM_DISK_LIST_HELP), - EFI_IFR_FLAG_CALLBACK, - 0, - NULL - ); - - Index++; - } + Index++; + } - HiiUpdateForm ( - ConfigPrivate->HiiHandle, - &gRamDiskFormSetGuid, - MAIN_FORM_ID, - StartOpCodeHandle, - EndOpCodeHandle - ); + HiiUpdateForm ( + ConfigPrivate->HiiHandle, + &gRamDiskFormSetGuid, + MAIN_FORM_ID, + StartOpCodeHandle, + EndOpCodeHandle + ); + HiiFreeOpCodeHandle (EndOpCodeHandle); + } - HiiFreeOpCodeHandle (StartOpCodeHandle); - HiiFreeOpCodeHandle (EndOpCodeHandle); + HiiFreeOpCodeHandle (StartOpCodeHandle); + } } /** diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c index 780cf0a016b2..7e822e993d1e 100644 --- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c +++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskProtocol.c @@ -167,7 +167,12 @@ RamDiskPublishNfit ( ASSERT (Status == EFI_BUFFER_TOO_SMALL); do { MemoryMap = (EFI_MEMORY_DESCRIPTOR *)AllocatePool (MemoryMapSize); - ASSERT (MemoryMap != NULL); + + if (MemoryMap == NULL) { + ASSERT (MemoryMap != NULL); + return EFI_OUT_OF_RESOURCES; + } + Status = gBS->GetMemoryMap ( &MemoryMapSize, MemoryMap, diff --git a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c index 86020de6e092..fb25b1fba6e6 100644 --- a/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c +++ b/MdeModulePkg/Universal/Disk/UdfDxe/FileSystemOperations.c @@ -1449,6 +1449,8 @@ InternalFindFile ( CHAR16 FoundFileName[UDF_FILENAME_LENGTH]; VOID *CompareFileEntry; + CompareFileEntry = NULL; + // // Check if both Parent->FileIdentifierDesc and Icb are NULL. // diff --git a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdSymbol.c b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdSymbol.c index 1b30b917f1c6..546fd96aad52 100644 --- a/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdSymbol.c +++ b/MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbCmdSymbol.c @@ -568,6 +568,8 @@ DebuggerUnloadSymbol ( UINTN Index; VOID *BufferPtr; + BufferPtr = NULL; + // // Check the argument // @@ -703,6 +705,8 @@ DebuggerLoadCode ( CHAR16 *FileName; CHAR16 *MapFileName; + Buffer = NULL; + // // Check the argument // @@ -800,6 +804,7 @@ DebuggerUnloadCode ( EFI_STATUS Status; VOID *BufferPtr; + BufferPtr = NULL; // // Check the argument // diff --git a/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmp.c b/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmp.c index 5bc627461dfc..bee71246a440 100644 --- a/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmp.c +++ b/MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmp.c @@ -103,6 +103,10 @@ IsSystemFmp ( Guid = PcdGetPtr (PcdSystemFmpCapsuleImageTypeIdGuid); Count = PcdGetSize (PcdSystemFmpCapsuleImageTypeIdGuid) / sizeof (GUID); + if (Guid == NULL) { + return FALSE; + } + for (Index = 0; Index < Count; Index++, Guid++) { if (CompareGuid (&FmpImageInfo->ImageTypeId, Guid)) { return TRUE; @@ -313,14 +317,14 @@ FmpGetFirmwareImageDescriptor ( ImageInfoSize = 0; Status = Fmp->GetImageInfo ( - Fmp, // FMP Pointer - &ImageInfoSize, // Buffer Size (in this case 0) - NULL, // NULL so we can get size - FmpImageInfoDescriptorVer, // DescriptorVersion - FmpImageInfoCount, // DescriptorCount - DescriptorSize, // DescriptorSize - &PackageVersion, // PackageVersion - &PackageVersionName // PackageVersionName + Fmp, // FMP Pointer + &ImageInfoSize, // Buffer Size (in this case 0) + NULL, // NULL so we can get size + FmpImageInfoDescriptorVer, // DescriptorVersion + FmpImageInfoCount, // DescriptorCount + DescriptorSize, // DescriptorSize + &PackageVersion, // PackageVersion + &PackageVersionName // PackageVersionName ); if (Status != EFI_BUFFER_TOO_SMALL) { DEBUG ((DEBUG_ERROR, "EsrtFmpDxe: Unexpected Failure in GetImageInfo. Status = %r\n", Status)); @@ -335,14 +339,14 @@ FmpGetFirmwareImageDescriptor ( PackageVersionName = NULL; Status = Fmp->GetImageInfo ( - Fmp, // FMP Pointer - &ImageInfoSize, // ImageInfoSize - FmpImageInfoBuf, // ImageInfo - FmpImageInfoDescriptorVer, // DescriptorVersion - FmpImageInfoCount, // DescriptorCount - DescriptorSize, // DescriptorSize - &PackageVersion, // PackageVersion - &PackageVersionName // PackageVersionName + Fmp, // FMP Pointer + &ImageInfoSize, // ImageInfoSize + FmpImageInfoBuf, // ImageInfo + FmpImageInfoDescriptorVer, // DescriptorVersion + FmpImageInfoCount, // DescriptorCount + DescriptorSize, // DescriptorSize + &PackageVersion, // PackageVersion + &PackageVersionName // PackageVersionName ); if (PackageVersionName != NULL) { FreePool (PackageVersionName); diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c index d442ccb52fc4..ca0096a69e36 100644 --- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c @@ -856,7 +856,7 @@ FtwGetLastWriteRecord ( OUT EFI_FAULT_TOLERANT_WRITE_RECORD **FtwWriteRecord ) { - UINTN Index; + UINT64 Index; EFI_FAULT_TOLERANT_WRITE_RECORD *FtwRecord; *FtwWriteRecord = NULL; diff --git a/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c b/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c index 8c152dcbad98..260e9adbf6e4 100644 --- a/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c +++ b/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c @@ -102,7 +102,7 @@ FtwGetLastWriteRecord ( // // Try to find the last write record "that has not completed" // - for (Index = 0; Index < FtwWriteHeader->NumberOfWrites; Index += 1) { + for (Index = 0; (UINT64)Index < FtwWriteHeader->NumberOfWrites; Index += 1) { if (FtwRecord->DestinationComplete != FTW_VALID_STATE) { // // The last write record is found diff --git a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c index 0252db19ade9..b35d79351b37 100644 --- a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c +++ b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c @@ -562,6 +562,11 @@ FvSimpleFileSystemOpen ( // NewFileNameLength = FileNameLength + 1 + 4 = (Number of non-null character) + (file extension) + (a null character) NewFileNameLength = FileNameLength + 1 + 4; FileNameWithExtension = AllocatePool (NewFileNameLength * 2); + + if (FileNameWithExtension == NULL) { + return EFI_OUT_OF_RESOURCES; + } + StrCpyS (FileNameWithExtension, NewFileNameLength, FileName); StrCatS (FileNameWithExtension, NewFileNameLength, L".EFI"); diff --git a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c index 3f96407dc755..7ec9725ae898 100644 --- a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c +++ b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystemEntryPoint.c @@ -450,7 +450,11 @@ FvSimpleFileSystemDriverStart ( // Create an instance // Instance = AllocateZeroPool (sizeof (FV_FILESYSTEM_INSTANCE)); - ASSERT (Instance != NULL); + + if (Instance == NULL) { + ASSERT (Instance != NULL); + return EFI_OUT_OF_RESOURCES; + } Instance->Root = NULL; Instance->FvProtocol = FvProtocol; diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c index 426dead981bb..fc10d29618cf 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigKeywordHandler.c @@ -1757,7 +1757,12 @@ ConstructConfigHdr ( if (AsciiName != NULL) { NameSize = AsciiStrSize (AsciiName); Name = AllocateZeroPool (NameSize * sizeof (CHAR16)); - ASSERT (Name != NULL); + + if (Name == NULL) { + ASSERT (Name != NULL); + return NULL; + } + AsciiStrToUnicodeStrS (AsciiName, Name, NameSize); } else { Name = NULL; @@ -1917,7 +1922,11 @@ ConstructRequestElement ( // Allocate buffer for the entire // StringPtr = AllocateZeroPool (Length * sizeof (CHAR16)); - ASSERT (StringPtr != NULL); + + if (StringPtr == NULL) { + ASSERT (StringPtr != NULL); + return NULL; + } if (Name != NULL) { // @@ -1976,6 +1985,10 @@ GetNameFromId ( GetEfiGlobalVariable2 (L"PlatformLang", (VOID **)&PlatformLanguage, NULL); SupportedLanguages = GetSupportedLanguages (DatabaseRecord->Handle); + if (SupportedLanguages == NULL) { + goto Done; + } + // // Get the best matching language from SupportedLanguages // @@ -2108,35 +2121,50 @@ ExtractConfigRequest ( Storage = FindStorageFromVarId (FormPackage, Header->VarStoreId); ASSERT (Storage != NULL); - if (((EFI_IFR_OP_HEADER *)Storage)->OpCode == EFI_IFR_VARSTORE_NAME_VALUE_OP) { - Name = GetNameFromId (DatabaseRecord, Header->VarStoreInfo.VarName); - } else { - Offset = Header->VarStoreInfo.VarOffset; - Width = GetWidth (OpCode); - } + if (Storage != NULL) { + if (((EFI_IFR_OP_HEADER *)Storage)->OpCode == EFI_IFR_VARSTORE_NAME_VALUE_OP) { + Name = GetNameFromId (DatabaseRecord, Header->VarStoreInfo.VarName); + } else { + Offset = Header->VarStoreInfo.VarOffset; + Width = GetWidth (OpCode); + } - RequestElement = ConstructRequestElement (Name, Offset, Width); - ConfigHdr = ConstructConfigHdr (Storage, DatabaseRecord->DriverHandle); - ASSERT (ConfigHdr != NULL); + RequestElement = ConstructRequestElement (Name, Offset, Width); - MaxLen = StrLen (ConfigHdr) + 1 + StrLen (RequestElement) + 1; - *ConfigRequest = AllocatePool (MaxLen * sizeof (CHAR16)); - if (*ConfigRequest == NULL) { - FreePool (ConfigHdr); - FreePool (RequestElement); - return EFI_OUT_OF_RESOURCES; - } + if (RequestElement == NULL) { + return EFI_OUT_OF_RESOURCES; + } - StringPtr = *ConfigRequest; + ConfigHdr = ConstructConfigHdr (Storage, DatabaseRecord->DriverHandle); - StrCpyS (StringPtr, MaxLen, ConfigHdr); + if (ConfigHdr == NULL) { + ASSERT (ConfigHdr != NULL); + FreePool (RequestElement); + return EFI_OUT_OF_RESOURCES; + } - StrCatS (StringPtr, MaxLen, L"&"); + if (ConfigHdr != NULL) { + MaxLen = StrLen (ConfigHdr) + 1 + StrLen (RequestElement) + 1; + *ConfigRequest = AllocatePool (MaxLen * sizeof (CHAR16)); + if (*ConfigRequest == NULL) { + FreePool (ConfigHdr); + FreePool (RequestElement); + return EFI_OUT_OF_RESOURCES; + } + + StringPtr = *ConfigRequest; + + StrCpyS (StringPtr, MaxLen, ConfigHdr); - StrCatS (StringPtr, MaxLen, RequestElement); + StrCatS (StringPtr, MaxLen, L"&"); - FreePool (ConfigHdr); - FreePool (RequestElement); + StrCatS (StringPtr, MaxLen, RequestElement); + + FreePool (ConfigHdr); + } + + FreePool (RequestElement); + } return EFI_SUCCESS; } @@ -2213,44 +2241,53 @@ ExtractConfigResp ( Storage = FindStorageFromVarId (FormPackage, Header->VarStoreId); ASSERT (Storage != NULL); - if (((EFI_IFR_OP_HEADER *)Storage)->OpCode == EFI_IFR_VARSTORE_NAME_VALUE_OP) { - Name = GetNameFromId (DatabaseRecord, Header->VarStoreInfo.VarName); - } else { - Offset = Header->VarStoreInfo.VarOffset; - Width = GetWidth (OpCode); - } + if (Storage != NULL) { + if (((EFI_IFR_OP_HEADER *)Storage)->OpCode == EFI_IFR_VARSTORE_NAME_VALUE_OP) { + Name = GetNameFromId (DatabaseRecord, Header->VarStoreInfo.VarName); + } else { + Offset = Header->VarStoreInfo.VarOffset; + Width = GetWidth (OpCode); + } - RequestElement = ConstructRequestElement (Name, Offset, Width); + RequestElement = ConstructRequestElement (Name, Offset, Width); - ConfigHdr = ConstructConfigHdr (Storage, DatabaseRecord->DriverHandle); - ASSERT (ConfigHdr != NULL); + if (RequestElement == NULL) { + return EFI_OUT_OF_RESOURCES; + } - MaxLen = StrLen (ConfigHdr) + 1 + StrLen (RequestElement) + 1 + StrLen (L"VALUE=") + StrLen (ValueElement) + 1; - *ConfigResp = AllocatePool (MaxLen * sizeof (CHAR16)); - if (*ConfigResp == NULL) { - FreePool (ConfigHdr); - FreePool (RequestElement); - return EFI_OUT_OF_RESOURCES; - } + ConfigHdr = ConstructConfigHdr (Storage, DatabaseRecord->DriverHandle); + ASSERT (ConfigHdr != NULL); - StringPtr = *ConfigResp; + if (ConfigHdr != NULL) { + MaxLen = StrLen (ConfigHdr) + 1 + StrLen (RequestElement) + 1 + StrLen (L"VALUE=") + StrLen (ValueElement) + 1; + *ConfigResp = AllocatePool (MaxLen * sizeof (CHAR16)); + if (*ConfigResp == NULL) { + FreePool (ConfigHdr); + FreePool (RequestElement); + return EFI_OUT_OF_RESOURCES; + } - StrCpyS (StringPtr, MaxLen, ConfigHdr); + StringPtr = *ConfigResp; - StrCatS (StringPtr, MaxLen, L"&"); + StrCpyS (StringPtr, MaxLen, ConfigHdr); - StrCatS (StringPtr, MaxLen, RequestElement); + StrCatS (StringPtr, MaxLen, L"&"); - StrCatS (StringPtr, MaxLen, L"&"); + StrCatS (StringPtr, MaxLen, RequestElement); - StrCatS (StringPtr, MaxLen, L"VALUE="); + StrCatS (StringPtr, MaxLen, L"&"); - StrCatS (StringPtr, MaxLen, ValueElement); + StrCatS (StringPtr, MaxLen, L"VALUE="); - FreePool (ConfigHdr); - FreePool (RequestElement); + StrCatS (StringPtr, MaxLen, ValueElement); - return EFI_SUCCESS; + FreePool (ConfigHdr); + } + + FreePool (RequestElement); + + return EFI_SUCCESS; + } } } @@ -2299,21 +2336,24 @@ ExtractValueFromDriver ( // StringPtr = StrStr (Result, L"&VALUE="); ASSERT (StringPtr != NULL); - StringEnd = StrStr (StringPtr + 1, L"&"); - if (StringEnd != NULL) { - *StringEnd = L'\0'; - } - *ValueElement = AllocateCopyPool (StrSize (StringPtr), StringPtr); - if (*ValueElement == NULL) { - return EFI_OUT_OF_RESOURCES; - } + if (StringPtr != NULL) { + StringEnd = StrStr (StringPtr + 1, L"&"); + if (StringEnd != NULL) { + *StringEnd = L'\0'; + } - if (StringEnd != NULL) { - *StringEnd = L'&'; - } + *ValueElement = AllocateCopyPool (StrSize (StringPtr), StringPtr); + if (*ValueElement == NULL) { + return EFI_OUT_OF_RESOURCES; + } - FreePool (Result); + if (StringEnd != NULL) { + *StringEnd = L'&'; + } + + FreePool (Result); + } return EFI_SUCCESS; } diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c index 5ae6189a2843..7eae9bbf9a7b 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c @@ -7,6 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "HiiDatabase.h" +#include extern HII_DATABASE_PRIVATE_DATA mPrivate; /** @@ -248,7 +249,11 @@ GenerateSubStr ( // Length = StrLen (String) + BufferLen * 2 + 1 + 1; Str = AllocateZeroPool (Length * sizeof (CHAR16)); - ASSERT (Str != NULL); + + if (Str == NULL) { + ASSERT (Str != NULL); + return; + } StrCpyS (Str, Length, String); @@ -625,6 +630,7 @@ CompareBlockElementDefault ( UINTN TotalSize; BOOLEAN FoundOffset; + Status = EFI_SUCCESS; AppendString = NULL; TempBuffer = NULL; // @@ -632,12 +638,21 @@ CompareBlockElementDefault ( // AltConfigHdrPtr = StrStr (DefaultAltCfgResp, AltConfigHdr); ASSERT (AltConfigHdrPtr != NULL); + + if (AltConfigHdrPtr == NULL) { + goto Exit; + } + BlockPtr = StrStr (AltConfigHdrPtr, L"&OFFSET="); // // Make StringPtr point to the AltConfigHdr in ConfigAltResp. // StringPtr = StrStr (*ConfigAltResp, AltConfigHdr); - ASSERT (StringPtr != NULL); + + if (StringPtr == NULL) { + ASSERT (StringPtr != NULL); + goto Exit; + } while (BlockPtr != NULL) { // @@ -683,6 +698,12 @@ CompareBlockElementDefault ( // if (AppendString == NULL) { AppendString = (EFI_STRING)AllocateZeroPool (AppendSize + sizeof (CHAR16)); + + if (AppendString == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Exit; + } + StrnCatS (AppendString, AppendSize / sizeof (CHAR16) + 1, BlockPtrStart, AppendSize / sizeof (CHAR16)); } else { TotalSize = StrSize (AppendString) + AppendSize + sizeof (CHAR16); @@ -771,6 +792,7 @@ CompareNameElementDefault ( UINTN AppendSize; UINTN TotalSize; + Status = EFI_SUCCESS; AppendString = NULL; NvConfigExist = NULL; // @@ -778,15 +800,32 @@ CompareNameElementDefault ( // NvConfigPtr = StrStr (DefaultAltCfgResp, AltConfigHdr); ASSERT (NvConfigPtr != NULL); + + if (NvConfigPtr == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Exit; + } + NvConfigPtr = StrStr (NvConfigPtr + StrLen (AltConfigHdr), L"&"); // // Make StringPtr point to the first with AltConfigHdr in ConfigAltResp. // StringPtr = StrStr (*ConfigAltResp, AltConfigHdr); ASSERT (StringPtr != NULL); + + if (StringPtr == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Exit; + } + StringPtr = StrStr (StringPtr + StrLen (AltConfigHdr), L"&"); ASSERT (StringPtr != NULL); + if (StringPtr == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Exit; + } + while (NvConfigPtr != NULL) { // // ::=