MdeModulePkg: Fix conditionally uninitialized variables

Fixes CodeQL alerts for CWE-457:
https://cwe.mitre.org/data/definitions/457.html

Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Erich McMillan <emcmillan@microsoft.com>
Cc: Guomin Jiang <guomin.jiang@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Michael Kubacki <mikuback@linux.microsoft.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Zhichao Gao <zhichao.gao@intel.com>
Co-authored-by: Erich McMillan <emcmillan@microsoft.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
Reviewed-by: Oliver Smith-Denny <osd@smith-denny.com>
This commit is contained in:
Michael Kubacki
2022-11-08 15:24:54 -05:00
committed by mergify[bot]
parent 84d77d9bf5
commit 07251f3c6a
9 changed files with 80 additions and 56 deletions

View File

@ -1407,6 +1407,7 @@ SupportPaletteSnoopAttributes (
IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation IN EFI_PCI_IO_PROTOCOL_ATTRIBUTE_OPERATION Operation
) )
{ {
EFI_STATUS Status;
PCI_IO_DEVICE *Temp; PCI_IO_DEVICE *Temp;
UINT16 VGACommand; UINT16 VGACommand;
@ -1444,13 +1445,13 @@ SupportPaletteSnoopAttributes (
// Check if they are on the same bus // Check if they are on the same bus
// //
if (Temp->Parent == PciIoDevice->Parent) { if (Temp->Parent == PciIoDevice->Parent) {
PCI_READ_COMMAND_REGISTER (Temp, &VGACommand); Status = PCI_READ_COMMAND_REGISTER (Temp, &VGACommand);
// //
// If they are on the same bus, either one can // If they are on the same bus, either one can
// be set to snoop, the other set to decode // be set to snoop, the other set to decode
// //
if ((VGACommand & EFI_PCI_COMMAND_VGA_PALETTE_SNOOP) != 0) { if (!EFI_ERROR (Status) && ((VGACommand & EFI_PCI_COMMAND_VGA_PALETTE_SNOOP) != 0)) {
// //
// VGA has set to snoop, so GFX can be only set to disable snoop // VGA has set to snoop, so GFX can be only set to disable snoop
// //

View File

@ -730,10 +730,12 @@ Uhci2ControlTransfer (
Uhc->PciIo->Flush (Uhc->PciIo); Uhc->PciIo->Flush (Uhc->PciIo);
*TransferResult = QhResult.Result; if (!EFI_ERROR (Status)) {
*TransferResult = QhResult.Result;
if (DataLength != NULL) { if (DataLength != NULL) {
*DataLength = QhResult.Complete; *DataLength = QhResult.Complete;
}
} }
UhciDestoryTds (Uhc, TDs); UhciDestoryTds (Uhc, TDs);
@ -884,9 +886,11 @@ Uhci2BulkTransfer (
Uhc->PciIo->Flush (Uhc->PciIo); Uhc->PciIo->Flush (Uhc->PciIo);
*TransferResult = QhResult.Result; if (!EFI_ERROR (Status)) {
*DataToggle = QhResult.NextToggle; *TransferResult = QhResult.Result;
*DataLength = QhResult.Complete; *DataToggle = QhResult.NextToggle;
*DataLength = QhResult.Complete;
}
UhciDestoryTds (Uhc, TDs); UhciDestoryTds (Uhc, TDs);
Uhc->PciIo->Unmap (Uhc->PciIo, DataMap); Uhc->PciIo->Unmap (Uhc->PciIo, DataMap);
@ -1210,9 +1214,11 @@ Uhci2SyncInterruptTransfer (
UhciUnlinkTdFromQh (Uhc->SyncIntQh, TDs); UhciUnlinkTdFromQh (Uhc->SyncIntQh, TDs);
Uhc->PciIo->Flush (Uhc->PciIo); Uhc->PciIo->Flush (Uhc->PciIo);
*TransferResult = QhResult.Result; if (!EFI_ERROR (Status)) {
*DataToggle = QhResult.NextToggle; *TransferResult = QhResult.Result;
*DataLength = QhResult.Complete; *DataToggle = QhResult.NextToggle;
*DataLength = QhResult.Complete;
}
UhciDestoryTds (Uhc, TDs); UhciDestoryTds (Uhc, TDs);
Uhc->PciIo->Unmap (Uhc->PciIo, DataMap); Uhc->PciIo->Unmap (Uhc->PciIo, DataMap);

View File

@ -449,14 +449,15 @@ PromoteMemoryResource (
// //
Promoted = PromoteGuardedFreePages (&StartAddress, &EndAddress); Promoted = PromoteGuardedFreePages (&StartAddress, &EndAddress);
if (Promoted) { if (Promoted) {
CoreGetMemorySpaceDescriptor (StartAddress, &Descriptor); if (!EFI_ERROR (CoreGetMemorySpaceDescriptor (StartAddress, &Descriptor))) {
CoreAddRange ( CoreAddRange (
EfiConventionalMemory, EfiConventionalMemory,
StartAddress, StartAddress,
EndAddress, EndAddress,
Descriptor.Capabilities & ~(EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED | Descriptor.Capabilities & ~(EFI_MEMORY_PRESENT | EFI_MEMORY_INITIALIZED |
EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME) EFI_MEMORY_TESTED | EFI_MEMORY_RUNTIME)
); );
}
} }
} }

View File

@ -909,23 +909,28 @@ BootFromFile (
IN EFI_DEVICE_PATH_PROTOCOL *FilePath IN EFI_DEVICE_PATH_PROTOCOL *FilePath
) )
{ {
EFI_STATUS Status;
EFI_BOOT_MANAGER_LOAD_OPTION BootOption; EFI_BOOT_MANAGER_LOAD_OPTION BootOption;
CHAR16 *FileName; CHAR16 *FileName;
Status = EFI_NOT_STARTED;
FileName = NULL; FileName = NULL;
FileName = ExtractFileNameFromDevicePath (FilePath); FileName = ExtractFileNameFromDevicePath (FilePath);
if (FileName != NULL) { if (FileName != NULL) {
EfiBootManagerInitializeLoadOption ( Status = EfiBootManagerInitializeLoadOption (
&BootOption, &BootOption,
0, 0,
LoadOptionTypeBoot, LoadOptionTypeBoot,
LOAD_OPTION_ACTIVE, LOAD_OPTION_ACTIVE,
FileName, FileName,
FilePath, FilePath,
NULL, NULL,
0 0
); );
}
if (!EFI_ERROR (Status)) {
// //
// Since current no boot from removable media directly is allowed */ // Since current no boot from removable media directly is allowed */
// //

View File

@ -1075,7 +1075,10 @@ LibCreateNewFile (
NewHandle = NULL; NewHandle = NULL;
FullFileName = NULL; FullFileName = NULL;
LibGetFileHandleFromDevicePath (gFileExplorerPrivate.RetDevicePath, &FileHandle, &ParentName, &DeviceHandle); if (EFI_ERROR (LibGetFileHandleFromDevicePath (gFileExplorerPrivate.RetDevicePath, &FileHandle, &ParentName, &DeviceHandle))) {
return EFI_DEVICE_ERROR;
}
FullFileName = LibAppendFileName (ParentName, FileName); FullFileName = LibAppendFileName (ParentName, FileName);
if (FullFileName == NULL) { if (FullFileName == NULL) {
return EFI_OUT_OF_RESOURCES; return EFI_OUT_OF_RESOURCES;

View File

@ -691,6 +691,7 @@ BdsEntry (
EFI_DEVICE_PATH_PROTOCOL *FilePath; EFI_DEVICE_PATH_PROTOCOL *FilePath;
EFI_STATUS BootManagerMenuStatus; EFI_STATUS BootManagerMenuStatus;
EFI_BOOT_MANAGER_LOAD_OPTION PlatformDefaultBootOption; EFI_BOOT_MANAGER_LOAD_OPTION PlatformDefaultBootOption;
BOOLEAN PlatformDefaultBootOptionValid;
HotkeyTriggered = NULL; HotkeyTriggered = NULL;
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
@ -809,24 +810,24 @@ BdsEntry (
CpuDeadLoop (); CpuDeadLoop ();
} }
Status = EfiBootManagerInitializeLoadOption ( PlatformDefaultBootOptionValid = EfiBootManagerInitializeLoadOption (
&PlatformDefaultBootOption, &PlatformDefaultBootOption,
LoadOptionNumberUnassigned, LoadOptionNumberUnassigned,
LoadOptionTypePlatformRecovery, LoadOptionTypePlatformRecovery,
LOAD_OPTION_ACTIVE, LOAD_OPTION_ACTIVE,
L"Default PlatformRecovery", L"Default PlatformRecovery",
FilePath, FilePath,
NULL, NULL,
0 0
); ) == EFI_SUCCESS;
ASSERT_EFI_ERROR (Status); ASSERT (PlatformDefaultBootOptionValid == TRUE);
// //
// System firmware must include a PlatformRecovery#### variable specifying // System firmware must include a PlatformRecovery#### variable specifying
// a short-form File Path Media Device Path containing the platform default // a short-form File Path Media Device Path containing the platform default
// file path for removable media if the platform supports Platform Recovery. // file path for removable media if the platform supports Platform Recovery.
// //
if (PcdGetBool (PcdPlatformRecoverySupport)) { if (PlatformDefaultBootOptionValid && PcdGetBool (PcdPlatformRecoverySupport)) {
LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery); LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery);
if (EfiBootManagerFindLoadOption (&PlatformDefaultBootOption, LoadOptions, LoadOptionCount) == -1) { if (EfiBootManagerFindLoadOption (&PlatformDefaultBootOption, LoadOptions, LoadOptionCount) == -1) {
for (Index = 0; Index < LoadOptionCount; Index++) { for (Index = 0; Index < LoadOptionCount; Index++) {
@ -1104,15 +1105,17 @@ BdsEntry (
LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery); LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery);
ProcessLoadOptions (LoadOptions, LoadOptionCount); ProcessLoadOptions (LoadOptions, LoadOptionCount);
EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount); EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount);
} else { } else if (PlatformDefaultBootOptionValid) {
// //
// When platform recovery is not enabled, still boot to platform default file path. // When platform recovery is not enabled, still boot to platform default file path.
// //
EfiBootManagerProcessLoadOption (&PlatformDefaultBootOption); PlatformDefaultBootOptionValid = EfiBootManagerProcessLoadOption (&PlatformDefaultBootOption) == EFI_SUCCESS;
} }
} }
EfiBootManagerFreeLoadOption (&PlatformDefaultBootOption); if (PlatformDefaultBootOptionValid) {
EfiBootManagerFreeLoadOption (&PlatformDefaultBootOption);
}
DEBUG ((DEBUG_ERROR, "[Bds] Unable to boot!\n")); DEBUG ((DEBUG_ERROR, "[Bds] Unable to boot!\n"));
PlatformBootManagerUnableToBoot (); PlatformBootManagerUnableToBoot ();

View File

@ -944,13 +944,14 @@ PrintMismatchMenuInfo (
UINTN FormsetBufferSize; UINTN FormsetBufferSize;
Question = MenuOption->ThisTag; Question = MenuOption->ThisTag;
HiiGetFormSetFromHiiHandle (gFormData->HiiHandle, &FormsetBuffer, &FormsetBufferSize);
FormSetTitleStr = GetToken (FormsetBuffer->FormSetTitle, gFormData->HiiHandle); if (!EFI_ERROR (HiiGetFormSetFromHiiHandle (gFormData->HiiHandle, &FormsetBuffer, &FormsetBufferSize))) {
FormTitleStr = GetToken (gFormData->FormTitle, gFormData->HiiHandle); FormSetTitleStr = GetToken (FormsetBuffer->FormSetTitle, gFormData->HiiHandle);
FormTitleStr = GetToken (gFormData->FormTitle, gFormData->HiiHandle);
DEBUG ((DEBUG_ERROR, "\n[%a]: Mismatch Formset : Formset Guid = %g, FormSet title = %s\n", gEfiCallerBaseName, &gFormData->FormSetGuid, FormSetTitleStr)); DEBUG ((DEBUG_ERROR, "\n[%a]: Mismatch Formset : Formset Guid = %g, FormSet title = %s\n", gEfiCallerBaseName, &gFormData->FormSetGuid, FormSetTitleStr));
DEBUG ((DEBUG_ERROR, "[%a]: Mismatch Form : FormId = %d, Form title = %s.\n", gEfiCallerBaseName, gFormData->FormId, FormTitleStr)); DEBUG ((DEBUG_ERROR, "[%a]: Mismatch Form : FormId = %d, Form title = %s.\n", gEfiCallerBaseName, gFormData->FormId, FormTitleStr));
}
if (Question->OpCode->OpCode == EFI_IFR_ORDERED_LIST_OP) { if (Question->OpCode->OpCode == EFI_IFR_ORDERED_LIST_OP) {
QuestionName = GetToken (((EFI_IFR_ORDERED_LIST *)MenuOption->ThisTag->OpCode)->Question.Header.Prompt, gFormData->HiiHandle); QuestionName = GetToken (((EFI_IFR_ORDERED_LIST *)MenuOption->ThisTag->OpCode)->Question.Header.Prompt, gFormData->HiiHandle);

View File

@ -1745,6 +1745,7 @@ HiiStringToImage (
Attributes = (UINT8 *)AllocateZeroPool (StrLength * sizeof (UINT8)); Attributes = (UINT8 *)AllocateZeroPool (StrLength * sizeof (UINT8));
ASSERT (Attributes != NULL); ASSERT (Attributes != NULL);
FontInfo = NULL;
RowInfo = NULL; RowInfo = NULL;
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
StringIn2 = NULL; StringIn2 = NULL;
@ -1787,11 +1788,14 @@ HiiStringToImage (
Background = ((EFI_FONT_DISPLAY_INFO *)StringInfo)->BackgroundColor; Background = ((EFI_FONT_DISPLAY_INFO *)StringInfo)->BackgroundColor;
} else if (Status == EFI_SUCCESS) { } else if (Status == EFI_SUCCESS) {
FontInfo = &StringInfoOut->FontInfo; FontInfo = &StringInfoOut->FontInfo;
IsFontInfoExisted (Private, FontInfo, NULL, NULL, &GlobalFont); if (IsFontInfoExisted (Private, FontInfo, NULL, NULL, &GlobalFont)) {
Height = GlobalFont->FontPackage->Height; Height = GlobalFont->FontPackage->Height;
BaseLine = GlobalFont->FontPackage->BaseLine; BaseLine = GlobalFont->FontPackage->BaseLine;
Foreground = StringInfoOut->ForegroundColor; Foreground = StringInfoOut->ForegroundColor;
Background = StringInfoOut->BackgroundColor; Background = StringInfoOut->BackgroundColor;
} else {
goto Exit;
}
} else { } else {
goto Exit; goto Exit;
} }

View File

@ -2453,7 +2453,7 @@ VariableServiceGetVariable (
AcquireLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock); AcquireLockOnlyAtBootTime (&mVariableModuleGlobal->VariableGlobal.VariableServicesLock);
Status = FindVariable (VariableName, VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE); Status = FindVariable (VariableName, VendorGuid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE);
if ((Variable.CurrPtr == NULL) || EFI_ERROR (Status)) { if (EFI_ERROR (Status) || (Variable.CurrPtr == NULL)) {
goto Done; goto Done;
} }