Skip to content

Commit

Permalink
MdeModulePkg: Additional codeql fixes (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
apop5 authored and kenlautner committed May 9, 2023
1 parent 8b97e86 commit f6bdadf
Show file tree
Hide file tree
Showing 50 changed files with 1,367 additions and 1,039 deletions.
13 changes: 12 additions & 1 deletion CodeQlFilters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
"-NetworkPkg/Ip6Dxe/Ip6Output.c:cpp/likely-bugs/memory-management/v2/conditionally-uninitialized-variable",
"-ShellPkg/Application/Shell/ShellManParser.c:cpp/redundant-null-check-param",
"-ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Aest/AestParser.c:cpp/overflow-buffer",
"-ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c:cpp/overflow-buffer"
"-ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Iort/IortParser.c:cpp/overflow-buffer",

"-MdeModulePkg/Universal/Disk/UdfDxe/FileName.c:cpp/uselesstest",
"-MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c:SM02311",
"-MdeModulePkg/Universal/DriverSampleDxe/**:*",
"-MdeModulePkg/Universal/EbcDxe/EbcDebugger/EdbSupportString.c:cpp/uselesstest",
"-MdeModulePkg/Universal/RegularExpressionDxe/oniguruma/src/**.c:*",
"-MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c:cpp/unguardednullreturndereference",
"-MdeModulePkg/Universal/Acpi/S3SaveStateDxe/AcpiS3ContextSave.c:cpp/unguardednulllreturndereference",
"-MdeModulePkg/Universal/Disk/UdfDxe/FileName.c:cpp/uselesstest",
"-MdeModulePkg/Universal/BdsDxe/BdsEntry.c:cpp/unguardednullreturndereference",
"-MdeModulePkg/Core/Pei/Ppi/Ppi.c:cpp/overflow-buffer",
]
}
115 changes: 59 additions & 56 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;
// MU_CHANGE - Verify InitializeBootMenuData returned valid data
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
3 changes: 2 additions & 1 deletion MdeModulePkg/Application/CapsuleApp/CapsuleDump.c
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,8 @@ DumpProvisionedCapsule (
//
// Display description and device path
//
GetEfiSysPartitionFromBootOptionFilePath (BootNextOptionEntry.FilePath, &DevicePath, &Fs);
// MU_CHANGE - Get Status from GetEfiSysPartitionFromBootOptionFilePath
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
7 changes: 6 additions & 1 deletion MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,12 @@ GetUpdateFileSystem (
// If map is assigned, try to get ESP from mapped Fs.
//
DevicePath = DuplicateDevicePath (MappedDevicePath);
Status = GetEfiSysPartitionFromDevPath (DevicePath, &FullPath, Fs);
// MU_CHANGE - Check DuplicateDevicePath returned a Non-Null device path
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
2 changes: 2 additions & 0 deletions MdeModulePkg/Application/MpServicesTest/Options.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ ParseArguments (
PrintUsage ();
}

// MU_CHANGE - init Value to NULL due to code path that would leave it uninitialized
Value = NULL;
ZeroMem (Options, sizeof (MP_SERVICES_TEST_OPTIONS));

for (ArgIndex = 1; ArgIndex < Argc; ArgIndex++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,13 @@ DumpSmiHandler (

Print (L">\n");
ImageStruct = GetImageFromRef ((UINTN)SmiHandlerStruct->ImageRef);
NameString = GetDriverNameString (ImageStruct);
// MU_CHANGE - 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
72 changes: 39 additions & 33 deletions MdeModulePkg/Application/UiApp/FrontPage.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,40 +205,44 @@ UpdateFrontPageForm (
//
StartOpCodeHandle = HiiAllocateOpCodeHandle ();
ASSERT (StartOpCodeHandle != NULL);
// MU_CHANGE - Check StartOpCodeHandle and EndOpCodeHandle are valid
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 +980,9 @@ InitializeUserInterface (
UiSetConsoleMode (FALSE);

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

return EFI_SUCCESS;
}
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; // MU_CHANGE - comparison mismatch
UINTN Increment;
UINT16 *Buffer16;
EFI_STATUS Status;
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; // MU_CHANGE - comparison mismatch
UINT64 PrpListBase;
UINTN PrpListIndex;
UINTN PrpEntryIndex;
UINT64 PrpListIndex; // MU_CHANGE - comparison mismatch
UINT64 PrpEntryIndex; // MU_CHANGE - comparison mismatch
UINT64 Remainder;
EFI_PHYSICAL_ADDRESS PrpListPhyAddr;
UINTN Bytes;
Expand Down
12 changes: 8 additions & 4 deletions MdeModulePkg/Bus/Pci/NvmExpressPei/NvmExpressPeiHci.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,14 +564,18 @@ 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));
// MU_CHANGE - Check return status of NVME_GET_VER macro
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) {
// MU_CHANGE - Check return status of NVME_GET_CAP macro
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", __FUNCTION__));
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; // MU_CHANGE comparison mismatch
UINTN PrpListNo;
UINT64 PrpListBase;
VOID *PrpListHost;
UINTN PrpListIndex;
UINTN PrpEntryIndex;
UINT64 PrpEntryIndex; // MU_CHANGE comparison mismatch
UINT64 Remainder;
EFI_PHYSICAL_ADDRESS PrpListPhyAddr;
UINTN Bytes;
Expand Down
Loading

0 comments on commit f6bdadf

Please sign in to comment.