summaryrefslogtreecommitdiffstats
path: root/usr.sbin/mkuboot
diff options
context:
space:
mode:
authormiod <miod@openbsd.org>2014-05-18 21:18:07 +0000
committermiod <miod@openbsd.org>2014-05-18 21:18:07 +0000
commit2756da3cc0c8ef9fe99dfa96f2f8670fcb6e8e28 (patch)
treec1fe275eca11c29ea4605b42b54d74eade27cf01 /usr.sbin/mkuboot
parent_PIC is an optional method, so we shouldn't be aborting the rest of the (diff)
downloadwireguard-openbsd-2756da3cc0c8ef9fe99dfa96f2f8670fcb6e8e28.tar.xz
wireguard-openbsd-2756da3cc0c8ef9fe99dfa96f2f8670fcb6e8e28.zip
Correctly handle files smaller than an ELF header; reported by drahn@bitrig
Diffstat (limited to 'usr.sbin/mkuboot')
-rw-r--r--usr.sbin/mkuboot/mkuboot.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/usr.sbin/mkuboot/mkuboot.c b/usr.sbin/mkuboot/mkuboot.c
index a3c95b9da31..8ecb79dd790 100644
--- a/usr.sbin/mkuboot/mkuboot.c
+++ b/usr.sbin/mkuboot/mkuboot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mkuboot.c,v 1.3 2013/10/28 09:00:06 patrick Exp $ */
+/* $OpenBSD: mkuboot.c,v 1.4 2014/05/18 21:18:07 miod Exp $ */
/*
* Copyright (c) 2008 Mark Kettenis
@@ -285,12 +285,10 @@ is_elf(int ifd, const char *iname)
nbytes = read(ifd, &ehdr, sizeof ehdr);
if (nbytes == -1)
err(1, "%s", iname);
- if (nbytes != sizeof ehdr)
- return 0;
-
if (lseek(ifd, 0, SEEK_SET) != 0)
err(1, "%s", iname);
- if (!IS_ELF(ehdr))
+
+ if (nbytes != sizeof ehdr || !IS_ELF(ehdr))
return 0;
if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)