Skip to content

Commit ed3abbf

Browse files
medhefgokeszybz
authored andcommitted
boot: Fix readdir_harder() on VirtualBox
Fixes: #22073
1 parent e07a804 commit ed3abbf

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Diff for: src/boot/efi/boot.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,7 @@ static void config_load_entries(
15771577
_cleanup_freepool_ CHAR8 *content = NULL;
15781578

15791579
err = readdir_harder(entries_dir, &f, &f_size);
1580-
if (f_size == 0 || EFI_ERROR(err))
1580+
if (EFI_ERROR(err) || !f)
15811581
break;
15821582

15831583
if (f->FileName[0] == '.')
@@ -2019,7 +2019,7 @@ static void config_entry_add_linux(
20192019
CHAR8 *key, *value;
20202020

20212021
err = readdir_harder(linux_dir, &f, &f_size);
2022-
if (f_size == 0 || EFI_ERROR(err))
2022+
if (EFI_ERROR(err) || !f)
20232023
break;
20242024

20252025
if (f->FileName[0] == '.')

Diff for: src/boot/efi/util.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,12 @@ EFI_STATUS readdir_harder(
592592
* the specified buffer needs to be freed by caller, after final use. */
593593

594594
if (!*buffer) {
595-
sz = offsetof(EFI_FILE_INFO, FileName) /* + 256 */;
595+
/* Some broken firmware violates the EFI spec by still advancing the readdir
596+
* position when returning EFI_BUFFER_TOO_SMALL, effectively skipping over any files when
597+
* the buffer was too small. Therefore, start with a buffer that should handle FAT32 max
598+
* file name length.
599+
* As a side effect, most readdir_harder() calls will now be slightly faster. */
600+
sz = sizeof(EFI_FILE_INFO) + 256 * sizeof(CHAR16);
596601
*buffer = xallocate_pool(sz);
597602
*buffer_size = sz;
598603
} else

0 commit comments

Comments
 (0)