]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Make file info size a constant 28640/head
authorJan Janssen <medhefgo@web.de>
Wed, 2 Aug 2023 14:21:51 +0000 (16:21 +0200)
committerJan Janssen <medhefgo@web.de>
Wed, 2 Aug 2023 14:22:42 +0000 (16:22 +0200)
src/boot/efi/proto/file-io.h
src/boot/efi/util.c

index 106c267fdfb286d22babb2034a3bfb99b22db2ae..57df9e111c1054e71d668767dd0acf1a58d81df8 100644 (file)
@@ -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;
index d2b8f882500f7d1a907ec21fe2c550fa7fd658df..3beab238d4bcd7d075deea972e267946d3f5355e 100644 (file)
@@ -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