Skip to content

Commit

Permalink
UefiBootManagerLib: Update assert condition in BmFindBootOptionInVari…
Browse files Browse the repository at this point in the history
…able() (microsoft#182)

Currently the following assertion is made in
`BmFindBootOptionInVariable()`:

```c
  if (OptionNumber == LoadOptionNumberUnassigned) {
    BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);

    if (BootOptions == NULL) {
      ASSERT (BootOptions != NULL);
      return LoadOptionNumberUnassigned;
    }

    Index = EfiBootManagerFindLoadOption (OptionToFind, BootOptions, BootOptionCount);
```

The reason behind this is to prevent passing a null pointer to
`EfiBootManagerFindLoadOption()`.

However, `EfiBootManagerFindLoadOption()` accepts a null pointer
argument to be passed as the second argument ('Array') as long as
the `Count` argument is `0`.

In that case `LoadOptionNumberUnassigned` will still be returned from
the function but an assert is not necessary.

This change updates the condition to only assert if the pointer is
null and the boot option count is non-zero.

- [ ] Breaking change?
- Will this change break pre-existing builds or functionality without
action being taken?
  **No**

Verified build and boot on Qemu35Pkg.

N/A

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
  • Loading branch information
makubacki committed Jun 26, 2024
1 parent 6e64615 commit 17628c8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ BmFindBootOptionInVariable (
if (OptionNumber == LoadOptionNumberUnassigned) {
BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);

// MU_CHANGE [BEGIN] - Only aassert if BootOptionCount is non-zero
if ((BootOptions == NULL) && (BootOptionCount > 0)) {
ASSERT (BootOptions != NULL);
return LoadOptionNumberUnassigned;
}

// MU_CHANGE [END] - Only aassert if BootOptionCount is non-zero

Index = EfiBootManagerFindLoadOption (OptionToFind, BootOptions, BootOptionCount);
if (Index != -1) {
OptionNumber = BootOptions[Index].OptionNumber;
Expand Down

0 comments on commit 17628c8

Please sign in to comment.