From: Gerd Hoffmann Date: Tue, 24 Jan 2023 09:28:25 +0000 (+0100) Subject: bootctl: tweak DOS header magic check X-Git-Tag: v254-rc1~1088^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=78088b8f43717a43661cd2c1627a9860904c4794;p=thirdparty%2Fsystemd.git bootctl: tweak DOS header magic check Read the magic first, try reading the full DOS exe header only in case the magic check succeeds. This avoids throwing an header read error on small dummy files as used by test-kernel-install. --- diff --git a/src/boot/bootctl-uki.c b/src/boot/bootctl-uki.c index e304cad06ae..261e687e3f8 100644 --- a/src/boot/bootctl-uki.c +++ b/src/boot/bootctl-uki.c @@ -31,11 +31,16 @@ static int pe_sections(FILE *uki, struct PeSectionHeader **ret, size_t *ret_n) { assert(ret_n); items = fread(&dos, 1, sizeof(dos), uki); - if (items != sizeof(dos)) - return log_error_errno(SYNTHETIC_ERRNO(EIO), "DOS header read error"); + if (items < sizeof(dos.Magic)) + return log_error_errno(SYNTHETIC_ERRNO(EIO), "File is smaller than DOS magic (got %"PRIu64" of %zu bytes)", + items, sizeof(dos.Magic)); if (memcmp(dos.Magic, dos_file_magic, sizeof(dos_file_magic)) != 0) goto no_sections; + if (items != sizeof(dos)) + return log_error_errno(SYNTHETIC_ERRNO(EIO), "File is smaller than DOS header (got %"PRIu64" of %zu bytes)", + items, sizeof(dos)); + if (fseek(uki, le32toh(dos.ExeHeader), SEEK_SET) < 0) return log_error_errno(errno, "seek to PE header");