diff options
| author | Michał Żygowski <michal.zygowski@3mdeb.com> | 2023-12-16 13:01:29 +0100 |
|---|---|---|
| committer | Peter Jones <pjones@redhat.com> | 2025-01-21 11:00:49 -0500 |
| commit | d6076cb61297c13a0c55c0b848b85b9f31a912ac (patch) | |
| tree | 911ae9de25ad2265f7e32e9a2c1391088e958a35 | |
| parent | 9415d3cada09f8043bb9a2c1b32fd1f909cefab0 (diff) | |
| download | efi-boot-shim-d6076cb61297c13a0c55c0b848b85b9f31a912ac.tar.gz efi-boot-shim-d6076cb61297c13a0c55c0b848b85b9f31a912ac.zip | |
simple_file: Use second variable to create filesystem entries
If HandleProtocol or OpenVolume fails, the entries array will become
non-contiguous, i.e. will have NULL pointers between valid volume
names in the array. Because of that count_lines may return a lower
number of entries than expected. As a result one may not browse all
valid filesystems in the file explorer.
Add a second index variable that will increment only on successfully
created filesystem entries. As a result, count_lines should return
proper length and there won't be any lost partitions or accesses to
invalid entries.
Signed-off-by: Michał Żygowski <michal.zygowski@3mdeb.com>
| -rw-r--r-- | lib/simple_file.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/simple_file.c b/lib/simple_file.c index fc082bed..6057f883 100644 --- a/lib/simple_file.c +++ b/lib/simple_file.c @@ -170,7 +170,7 @@ simple_file_write_all(EFI_FILE *file, UINTN size, void *buffer) EFI_STATUS simple_volume_selector(CHAR16 **title, CHAR16 **selected, EFI_HANDLE *h) { - UINTN count, i; + UINTN count, i, j; EFI_HANDLE *vol_handles = NULL; EFI_STATUS efi_status; CHAR16 **entries; @@ -188,7 +188,7 @@ simple_volume_selector(CHAR16 **title, CHAR16 **selected, EFI_HANDLE *h) if (!entries) return EFI_OUT_OF_RESOURCES; - for (i = 0; i < count; i++) { + for (i = 0, j = 0; i < count; i++) { char buf[4096]; UINTN size = sizeof(buf); EFI_FILE_SYSTEM_INFO *fi = (void *)buf; @@ -218,12 +218,12 @@ simple_volume_selector(CHAR16 **title, CHAR16 **selected, EFI_HANDLE *h) if (!name || StrLen(name) == 0 || StrCmp(name, L" ") == 0) name = DevicePathToStr(DevicePathFromHandle(vol_handles[i])); - entries[i] = AllocatePool((StrLen(name) + 2) * sizeof(CHAR16)); - if (!entries[i]) + entries[j] = AllocatePool((StrLen(name) + 2) * sizeof(CHAR16)); + if (!entries[j]) break; - StrCpy(entries[i], name); + StrCpy(entries[j++], name); } - entries[i] = NULL; + entries[j] = NULL; val = console_select(title, entries, 0); |
