Skip to content

Commit

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

## Description

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**

## How This Was Tested

Verified build and boot on Qemu35Pkg.

## Integration Instructions

N/A

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
  • Loading branch information
makubacki authored and kenlautner committed Oct 20, 2023
1 parent aafc944 commit 0c9d72f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ BmFindBootOptionInVariable (
if (OptionNumber == LoadOptionNumberUnassigned) {
BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);

if (BootOptions == NULL) {
if ((BootOptions == NULL) && (BootOptionCount > 0)) {
ASSERT (BootOptions != NULL);
return LoadOptionNumberUnassigned;
}
Expand Down

0 comments on commit 0c9d72f

Please sign in to comment.