Skip to content

Commit

Permalink
[CHERRY-PICK] MdeModulePkg/BootMaintenanceManagerUiLib: Check array i…
Browse files Browse the repository at this point in the history
…ndex before access

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]>
  • Loading branch information
makubacki committed Sep 9, 2023
1 parent 776244b commit d73eb13
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 d73eb13

Please sign in to comment.