From: Lennart Poettering Date: Tue, 3 Jan 2023 14:58:46 +0000 (+0100) Subject: efi: skip Read() calls with zero sizes X-Git-Tag: v253-rc1~195 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd1fec534e70891c1fe49779221d93236d8c5ac2;p=thirdparty%2Fsystemd.git efi: skip Read() calls with zero sizes Let's avoid calling Read() with zero-sized buffer, to avoid needless firmware quirkiness. See: #25911 --- diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index 2e657a8bf91..29996b88266 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -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; diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index d1e1aa59aec..b1c19a5c9bb 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -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);