summaryrefslogtreecommitdiff
path: root/MdeModulePkg
diff options
context:
space:
mode:
authorAaron Pop <aaronpop@microsoft.com>2025-10-22 21:33:02 +0300
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2026-08-05 06:07:16 +0300
commitdfd0edeb4e71f01f83cf9aa53285db4f14e5487d (patch)
treeeadf849879e2616b236bb70f85721a25e621d035 /MdeModulePkg
parent699382e3429a4ecd3ccd58d333f413e14bb10edc (diff)
downloadedk2-dfd0edeb4e71f01f83cf9aa53285db4f14e5487d.tar.xz
MdeModulePkg: Fix missing NULL tests
https://github.com/github/codeql/blob/codeql-cli-2.7.3/cpp/ql/src/Critical/MissingNullTest.qhelp For items which allocate memory, or get a pointer from another structure, it is important to validate that the pointers are not null before they are dereferenced. Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
Diffstat (limited to 'MdeModulePkg')
-rw-r--r--MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c6
-rw-r--r--MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c7
-rw-r--r--MdeModulePkg/Application/UiApp/FrontPage.c20
-rw-r--r--MdeModulePkg/Application/UiApp/FrontPageCustomizedUiSupport.c25
-rw-r--r--MdeModulePkg/Application/VariableInfo/VariableInfo.c7
5 files changed, 55 insertions, 10 deletions
diff --git a/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c b/MdeModulePkg/Application/CapsuleApp/CapsuleOnDisk.c
index 5ce5a50f7b..f1501ebcf4 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 68c2e35791..18415c056e 100644
--- a/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c
+++ b/MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.c
@@ -610,7 +610,12 @@ DumpSmiHandler (
Print (L">\n");
ImageStruct = GetImageFromRef ((UINTN)SmiHandlerStruct->ImageRef);
- NameString = GetDriverNameString (ImageStruct);
+ 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);
diff --git a/MdeModulePkg/Application/UiApp/FrontPage.c b/MdeModulePkg/Application/UiApp/FrontPage.c
index 56e174fe56..84fba400a2 100644
--- a/MdeModulePkg/Application/UiApp/FrontPage.c
+++ b/MdeModulePkg/Application/UiApp/FrontPage.c
@@ -203,10 +203,17 @@ UpdateFrontPageForm (
// Allocate space for creation of UpdateData Buffer
//
StartOpCodeHandle = HiiAllocateOpCodeHandle ();
- ASSERT (StartOpCodeHandle != NULL);
+ if (StartOpCodeHandle == NULL) {
+ ASSERT (StartOpCodeHandle != NULL);
+ return;
+ }
EndOpCodeHandle = HiiAllocateOpCodeHandle ();
- ASSERT (EndOpCodeHandle != NULL);
+ if (EndOpCodeHandle == NULL) {
+ ASSERT (EndOpCodeHandle != NULL);
+ goto Exit;
+ }
+
//
// Create Hii Extend Label OpCode as the start opcode
//
@@ -236,8 +243,10 @@ UpdateFrontPageForm (
EndOpCodeHandle
);
- HiiFreeOpCodeHandle (StartOpCodeHandle);
HiiFreeOpCodeHandle (EndOpCodeHandle);
+Exit:
+ HiiFreeOpCodeHandle (StartOpCodeHandle);
+ return;
}
/**
@@ -966,7 +975,10 @@ InitializeUserInterface (
// Install customized fonts needed by Front Page
//
HiiHandle = ExportFonts ();
- ASSERT (HiiHandle != NULL);
+ if (HiiHandle == NULL) {
+ ASSERT (HiiHandle != NULL);
+ return EFI_NOT_FOUND;
+ }
InitializeStringSupport ();
diff --git a/MdeModulePkg/Application/UiApp/FrontPageCustomizedUiSupport.c b/MdeModulePkg/Application/UiApp/FrontPageCustomizedUiSupport.c
index 24f9f1e3fb..ef6b527d18 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 {
@@ -346,7 +351,10 @@ UiCreateLanguageMenu (
OptionCount = 0;
if (Lang == NULL) {
Lang = AllocatePool (AsciiStrSize (gLanguageString));
- ASSERT (Lang != NULL);
+ if (Lang == NULL) {
+ ASSERT (Lang != NULL);
+ goto Exit;
+ }
}
while (*LangCode != 0) {
@@ -393,6 +401,7 @@ UiCreateLanguageMenu (
NULL
);
+Exit:
HiiFreeOpCodeHandle (OptionsOpCodeHandle);
}
@@ -592,10 +601,20 @@ UiListThirdPartyDrivers (
}
HiiHandles = HiiGetHiiHandles (NULL);
- ASSERT (HiiHandles != NULL);
+ if ( HiiHandles == NULL) {
+ ASSERT (HiiHandles != NULL);
+ DEBUG ((DEBUG_ERROR, "%a No HII handles found in the HII database\n", __func__));
+ return EFI_NOT_FOUND;
+ }
gHiiDriverList = AllocateZeroPool (UI_HII_DRIVER_LIST_SIZE * sizeof (UI_HII_DRIVER_INSTANCE));
- ASSERT (gHiiDriverList != NULL);
+ if (gHiiDriverList == NULL) {
+ ASSERT (gHiiDriverList != NULL);
+ DEBUG ((DEBUG_VERBOSE, "%a No memory for gHiiDriverList\n", __func__));
+ FreePool (HiiHandles);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
DriverListPtr = gHiiDriverList;
CurrentSize = UI_HII_DRIVER_LIST_SIZE;
diff --git a/MdeModulePkg/Application/VariableInfo/VariableInfo.c b/MdeModulePkg/Application/VariableInfo/VariableInfo.c
index 3dee41eb4b..13c4acc2f2 100644
--- a/MdeModulePkg/Application/VariableInfo/VariableInfo.c
+++ b/MdeModulePkg/Application/VariableInfo/VariableInfo.c
@@ -131,7 +131,12 @@ PrintInfoFromSmm (
Entry = (EFI_MEMORY_DESCRIPTOR *)((UINT8 *)Entry + PiSmmCommunicationRegionTable->DescriptorSize);
}
- ASSERT (CommBuffer != NULL);
+ if (CommBuffer == NULL) {
+ DEBUG ((DEBUG_ERROR, "Warning: No SMM communication buffer found!\n"));
+ ASSERT (CommBuffer != NULL);
+ return EFI_NOT_FOUND;
+ }
+
ZeroMem (CommBuffer, RealCommSize);
Print (L"SMM Driver Non-Volatile Variables:\n");