mirror of
https://github.com/tianocore/edk2
synced 2026-08-27 00:23:19 -04:00
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:
parent
af24f366a4
commit
1cc0af9d6d
6 changed files with 55 additions and 11 deletions
|
|
@ -1451,10 +1451,17 @@ CustomizeMenus (
|
|||
// 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
|
||||
//
|
||||
|
|
@ -1485,6 +1492,7 @@ CustomizeMenus (
|
|||
);
|
||||
|
||||
HiiFreeOpCodeHandle (StartOpCodeHandle);
|
||||
Exit:
|
||||
HiiFreeOpCodeHandle (EndOpCodeHandle);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -378,10 +378,18 @@ BmmListThirdPartyDrivers (
|
|||
}
|
||||
|
||||
HiiHandles = HiiGetHiiHandles (NULL);
|
||||
ASSERT (HiiHandles != NULL);
|
||||
if (HiiHandles == NULL) {
|
||||
ASSERT (HiiHandles != NULL);
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
gHiiDriverList = AllocateZeroPool (UI_HII_DRIVER_LIST_SIZE * sizeof (UI_HII_DRIVER_INSTANCE));
|
||||
ASSERT (gHiiDriverList != NULL);
|
||||
if (gHiiDriverList == NULL) {
|
||||
ASSERT (gHiiDriverList != NULL);
|
||||
FreePool (HiiHandles);
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
DriverListPtr = gHiiDriverList;
|
||||
CurrentSize = UI_HII_DRIVER_LIST_SIZE;
|
||||
|
||||
|
|
|
|||
|
|
@ -340,6 +340,10 @@ BOpt_GetBootOptions (
|
|||
|
||||
BootOption = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);
|
||||
for (Index = 0; Index < BootOrderListSize / sizeof (UINT16); Index++) {
|
||||
if (BootOption == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
// Don't display the hidden/inactive boot option
|
||||
//
|
||||
|
|
@ -363,7 +367,10 @@ BOpt_GetBootOptions (
|
|||
}
|
||||
|
||||
NewMenuEntry = BOpt_CreateMenuEntry (BM_LOAD_CONTEXT_SELECT);
|
||||
ASSERT (NULL != NewMenuEntry);
|
||||
if (NewMenuEntry == NULL) {
|
||||
ASSERT (NULL != NewMenuEntry);
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
NewLoadContext = (BM_LOAD_CONTEXT *)NewMenuEntry->VariableContext;
|
||||
|
||||
|
|
|
|||
|
|
@ -803,6 +803,10 @@ GetConsoleMenu (
|
|||
Index2 = 0;
|
||||
for (Index = 0; Index < AllCount; Index++) {
|
||||
DevicePathInst = GetNextDevicePathInstance (&MultiDevicePath, &Size);
|
||||
if (DevicePathInst == NULL) {
|
||||
ASSERT (DevicePathInst != NULL);
|
||||
continue;
|
||||
}
|
||||
|
||||
NewMenuEntry = BOpt_CreateMenuEntry (BM_CONSOLE_CONTEXT_SELECT);
|
||||
if (NULL == NewMenuEntry) {
|
||||
|
|
@ -813,7 +817,11 @@ GetConsoleMenu (
|
|||
NewMenuEntry->OptionNumber = Index2;
|
||||
|
||||
NewConsoleContext->DevicePath = DuplicateDevicePath (DevicePathInst);
|
||||
ASSERT (NewConsoleContext->DevicePath != NULL);
|
||||
if (NewConsoleContext->DevicePath == NULL) {
|
||||
ASSERT (NewConsoleContext->DevicePath != NULL);
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
NewMenuEntry->DisplayString = EfiLibStrFromDatahub (NewConsoleContext->DevicePath);
|
||||
if (NULL == NewMenuEntry->DisplayString) {
|
||||
NewMenuEntry->DisplayString = UiDevicePathToStr (NewConsoleContext->DevicePath);
|
||||
|
|
|
|||
|
|
@ -486,7 +486,10 @@ UpdateConsolePage (
|
|||
break;
|
||||
}
|
||||
|
||||
ASSERT (ConsoleCheck != NULL);
|
||||
if (ConsoleCheck == NULL) {
|
||||
ASSERT (ConsoleCheck != NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
for (Index = 0; ((Index < ConsoleMenu->MenuNumber) && \
|
||||
(Index < MAX_MENU_NUMBER)); Index++)
|
||||
|
|
@ -619,10 +622,16 @@ UpdateOrderPage (
|
|||
break;
|
||||
}
|
||||
|
||||
ASSERT (OptionOrder != NULL);
|
||||
if (OptionOrder == NULL ) {
|
||||
ASSERT (OptionOrder != NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
OptionsOpCodeHandle = HiiAllocateOpCodeHandle ();
|
||||
ASSERT (OptionsOpCodeHandle != NULL);
|
||||
if (OptionsOpCodeHandle == NULL) {
|
||||
ASSERT (OptionsOpCodeHandle != NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
NewMenuEntry = NULL;
|
||||
for (OptionIndex = 0; (OptionIndex < MAX_MENU_NUMBER && OptionOrder[OptionIndex] != 0); OptionIndex++) {
|
||||
|
|
@ -635,7 +644,7 @@ UpdateOrderPage (
|
|||
}
|
||||
}
|
||||
|
||||
if (BootOptionFound) {
|
||||
if (BootOptionFound && (NewMenuEntry != NULL)) {
|
||||
HiiCreateOneOfOptionOpCode (
|
||||
OptionsOpCodeHandle,
|
||||
NewMenuEntry->DisplayStringToken,
|
||||
|
|
|
|||
|
|
@ -197,7 +197,11 @@ Var_UpdateConsoleOption (
|
|||
NewTerminalContext->DevicePath,
|
||||
(EFI_DEVICE_PATH_PROTOCOL *)&Vendor
|
||||
);
|
||||
ASSERT (TerminalDevicePath != NULL);
|
||||
if (TerminalDevicePath == NULL) {
|
||||
ASSERT (TerminalDevicePath != NULL);
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
ChangeTerminalDevicePath (TerminalDevicePath, TRUE);
|
||||
ConDevicePath = AppendDevicePathInstance (
|
||||
ConDevicePath,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue