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>
This commit is contained in:
Aaron Pop 2025-10-22 11:33:02 -07:00 committed by mergify[bot]
parent dfd0edeb4e
commit 9b3ceeb254
3 changed files with 18 additions and 6 deletions

View file

@ -168,13 +168,14 @@ UpdateBlocksAndVolumes (
EFI_PEI_SERVICES **PeiServices;
IndexBlockDevice = 0;
BlockIo2Ppi = NULL;
BlockIoPpi = NULL;
//
// Find out all Block Io Ppi instances within the system
// Assuming all device Block Io Peims are dispatched already
//
for (BlockIoPpiInstance = 0; BlockIoPpiInstance < PEI_CD_EXPRESS_MAX_BLOCK_IO_PPI; BlockIoPpiInstance++) {
BlockIo2Ppi = NULL;
BlockIoPpi = NULL;
if (BlockIo2) {
Status = PeiServicesLocatePpi (
&gEfiPeiVirtualBlockIo2PpiGuid,

View file

@ -477,10 +477,16 @@ UpdateMainForm (
// Init OpCode Handle
//
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
@ -552,8 +558,9 @@ UpdateMainForm (
EndOpCodeHandle
);
HiiFreeOpCodeHandle (StartOpCodeHandle);
HiiFreeOpCodeHandle (EndOpCodeHandle);
Exit:
HiiFreeOpCodeHandle (StartOpCodeHandle);
}
/**

View file

@ -167,7 +167,11 @@ 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,