Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MdeModulePkg: CodeQL Fixes. #6266

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 58 additions & 55 deletions MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
6 changes: 5 additions & 1 deletion MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" <Module RefId=\"0x%x\" Name=\"%a\">\n", SmiHandlerStruct->ImageRef, NameString);
if ((ImageStruct != NULL) && (ImageStruct->PdbStringOffset != 0)) {
Print (L" <Pdb>%a</Pdb>\n", (UINT8 *)ImageStruct + ImageStruct->PdbStringOffset);
Expand Down
71 changes: 38 additions & 33 deletions MdeModulePkg/Application/UiApp/FrontPage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -976,7 +979,9 @@ InitializeUserInterface (
UiSetConsoleMode (FALSE);

UninitializeStringSupport ();
HiiRemovePackages (HiiHandle);
if (HiiHandle != NULL) {
HiiRemovePackages (HiiHandle);
}

return EFI_SUCCESS;
}
Expand Down
7 changes: 7 additions & 0 deletions MdeModulePkg/Application/UiApp/FrontPageCustomizedUiSupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -517,6 +522,8 @@ RequiredDriver (
UINTN TempSize;
BOOLEAN RetVal;

Buffer = NULL;

Status = HiiGetFormSetFromHiiHandle (HiiHandle, &Buffer, &BufferSize);
if (EFI_ERROR (Status)) {
return FALSE;
Expand Down
2 changes: 1 addition & 1 deletion MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ AtaPioDataInOut (
IN ATA_NONBLOCK_TASK *Task
)
{
UINTN WordCount;
UINT64 WordCount;
UINTN Increment;
UINT16 *Buffer16;
EFI_STATUS Status;
Expand Down
2 changes: 1 addition & 1 deletion MdeModulePkg/Bus/Pci/IdeBusPei/AtapiPeim.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ PciIoMemRead (
EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc;
EFI_STATUS Status;

Desc = NULL;
if (Buffer == NULL) {
return EFI_INVALID_PARAMETER;
}
Expand Down Expand Up @@ -377,6 +378,8 @@ PciIoMemWrite (
EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Desc;
EFI_STATUS Status;

Desc = NULL;

if (Buffer == NULL) {
return EFI_INVALID_PARAMETER;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1273,6 +1277,8 @@ NonCoherentPciIoMap (
EFI_GCD_MEMORY_SPACE_DESCRIPTOR GcdDescriptor;
BOOLEAN Bounce;

AllocAddress = NULL;

if ((HostAddress == NULL) ||
(NumberOfBytes == NULL) ||
(DeviceAddress == NULL) ||
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions MdeModulePkg/Bus/Pci/NvmExpressDxe/NvmExpressPassthru.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiHci.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiPassThru.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading
Loading