From: miod Date: Sun, 18 May 2014 21:18:07 +0000 (+0000) Subject: Correctly handle files smaller than an ELF header; reported by drahn@bitrig X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=2756da3cc0c8ef9fe99dfa96f2f8670fcb6e8e28;p=openbsd Correctly handle files smaller than an ELF header; reported by drahn@bitrig --- 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)