Skip to content

Commit

Permalink
MdeModulePkg/BootMaintenanceManagerUiLib: Check array index before ac…
Browse files Browse the repository at this point in the history
…cess

Many arrays are defined with a length of MAX_MENU_NUMBER in
FormGuid.h. Two of those are BootOptionOrder and DriverOptionOrder.

In UpdatePage.c, a pointer is set to either of those arrays. The
array buffer is accessed using an index whose range is checked after
the pointer to the array is dereferenced. This change moves the check
before the dereference.

In another place in the file, the ConsoleCheck pointer is also set to
an array buffer with MAX_MENU_NUMBER elements. Only an ASSERT()
currently checks the range of the array index. This change
conditionalizes the pointer dereference itself on the range of Index.

Cc: Jian J Wang <[email protected]>
Cc: Liming Gao <[email protected]>
Cc: Dandan Bi <[email protected]>
Cc: Eric Dong <[email protected]>
Signed-off-by: Michael Kubacki <[email protected]>
Reviewed-by: Dandan Bi <[email protected]>
  • Loading branch information
makubacki authored and mergify[bot] committed Sep 12, 2023
1 parent a5cbb59 commit e880c30
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions MdeModulePkg/Library/BootMaintenanceManagerUiLib/UpdatePage.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,12 @@ UpdateConsolePage (
((NewTerminalContext->IsStdErr != 0) && (UpdatePageId == FORM_CON_ERR_ID))
)
{
CheckFlags |= EFI_IFR_CHECKBOX_DEFAULT;
ConsoleCheck[Index] = TRUE;
} else {
CheckFlags |= EFI_IFR_CHECKBOX_DEFAULT;

if (Index < MAX_MENU_NUMBER) {
ConsoleCheck[Index] = TRUE;
}
} else if (Index < MAX_MENU_NUMBER) {
ConsoleCheck[Index] = FALSE;
}

Expand Down Expand Up @@ -622,7 +625,7 @@ UpdateOrderPage (
ASSERT (OptionsOpCodeHandle != NULL);

NewMenuEntry = NULL;
for (OptionIndex = 0; (OptionOrder[OptionIndex] != 0 && OptionIndex < MAX_MENU_NUMBER); OptionIndex++) {
for (OptionIndex = 0; (OptionIndex < MAX_MENU_NUMBER && OptionOrder[OptionIndex] != 0); OptionIndex++) {
BootOptionFound = FALSE;
for (Index = 0; Index < OptionMenu->MenuNumber; Index++) {
NewMenuEntry = BOpt_GetMenuEntry (OptionMenu, Index);
Expand Down

0 comments on commit e880c30

Please sign in to comment.