From: Jan Janssen Date: Wed, 2 Aug 2023 14:21:51 +0000 (+0200) Subject: boot: Make file info size a constant X-Git-Tag: v255-rc1~836^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F28640%2Fhead;p=thirdparty%2Fsystemd.git boot: Make file info size a constant --- diff --git a/src/boot/efi/proto/file-io.h b/src/boot/efi/proto/file-io.h index 106c267fdfb..57df9e111c1 100644 --- a/src/boot/efi/proto/file-io.h +++ b/src/boot/efi/proto/file-io.h @@ -31,6 +31,12 @@ typedef struct { char16_t FileName[]; } EFI_FILE_INFO; +/* Some broken firmware violates the EFI spec by still advancing the readdir + * position when returning EFI_BUFFER_TOO_SMALL, effectively skipping over any files when + * the buffer was too small. Therefore, we always start with a buffer that should handle FAT32 + * max file name length. */ +#define EFI_FILE_INFO_MIN_SIZE (sizeof(EFI_FILE_INFO) + 256 * sizeof(char16_t)) + typedef struct EFI_SIMPLE_FILE_SYSTEM_PROTOCOL EFI_SIMPLE_FILE_SYSTEM_PROTOCOL; struct EFI_SIMPLE_FILE_SYSTEM_PROTOCOL { uint64_t Revision; diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index d2b8f882500..3beab238d4b 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -412,7 +412,7 @@ void sort_pointer_array( } EFI_STATUS get_file_info(EFI_FILE *handle, EFI_FILE_INFO **ret, size_t *ret_size) { - size_t size = offsetof(EFI_FILE_INFO, FileName) + 256; + size_t size = EFI_FILE_INFO_MIN_SIZE; _cleanup_free_ EFI_FILE_INFO *fi = NULL; EFI_STATUS err; @@ -454,12 +454,7 @@ EFI_STATUS readdir( * the specified buffer needs to be freed by caller, after final use. */ if (!*buffer) { - /* Some broken firmware violates the EFI spec by still advancing the readdir - * position when returning EFI_BUFFER_TOO_SMALL, effectively skipping over any files when - * the buffer was too small. Therefore, start with a buffer that should handle FAT32 max - * file name length. - * As a side effect, most readdir() calls will now be slightly faster. */ - sz = sizeof(EFI_FILE_INFO) + 256 * sizeof(char16_t); + sz = EFI_FILE_INFO_MIN_SIZE; *buffer = xmalloc(sz); *buffer_size = sz; } else