Skip to content

Commit

Permalink
efi: skip Read() calls with zero sizes
Browse files Browse the repository at this point in the history
Let's avoid calling Read() with zero-sized buffer, to avoid needless firmware
quirkiness.

See: #25911
  • Loading branch information
poettering authored and bluca committed Jan 3, 2023
1 parent 4055750 commit fd1fec5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/boot/efi/boot.c
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions src/boot/efi/util.c
Expand Up @@ -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);
Expand Down

0 comments on commit fd1fec5

Please sign in to comment.