Skip to content

Commit

Permalink
simple_file: Use second variable to create filesystem entries
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
miczyg1 authored and vathpela committed Jan 21, 2025
1 parent 9415d3c commit d6076cb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/simple_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit d6076cb

Please sign in to comment.