]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
efi: skip Read() calls with zero sizes
authorLennart Poettering <lennart@poettering.net>
Tue, 3 Jan 2023 14:58:46 +0000 (15:58 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 3 Jan 2023 22:12:36 +0000 (23:12 +0100)
Let's avoid calling Read() with zero-sized buffer, to avoid needless firmware
quirkiness.

See: #25911

src/boot/efi/boot.c
src/boot/efi/util.c

index 2e657a8bf91932177eaf615da1a4b3adf692aa6f..29996b882666ed6e85cde0aee1c8f4ab57a65dc4 100644 (file)
@@ -2295,6 +2295,9 @@ static EFI_STATUS initrd_prepare(
                 if (err != EFI_SUCCESS)
                         return err;
 
+                if (info->FileSize == 0) /* Automatically skip over empty files */
+                        continue;
+
                 UINTN new_size, read_size = info->FileSize;
                 if (__builtin_add_overflow(size, read_size, &new_size))
                         return EFI_OUT_OF_RESOURCES;
index d1e1aa59aec672d89d027d82f7bdb92032656b35..b1c19a5c9bba5f0c0e8d2f663a43c87fa26cd1fa 100644 (file)
@@ -326,9 +326,11 @@ EFI_STATUS file_read(EFI_FILE *dir, const char16_t *name, UINTN off, UINTN size,
         UINTN extra = size % sizeof(char16_t) + sizeof(char16_t);
 
         buf = xmalloc(size + extra);
-        err = handle->Read(handle, &size, buf);
-        if (err != EFI_SUCCESS)
-                return err;
+        if (size > 0) {
+                err = handle->Read(handle, &size, buf);
+                if (err != EFI_SUCCESS)
+                        return err;
+        }
 
         /* Note that handle->Read() changes size to reflect the actually bytes read. */
         memset(buf + size, 0, extra);