Subject: PR/9: Christoph Bield: Handle files without program headers gracefully Origin: FILE5_34-2-gedb7f0d6 Upstream-Author: Christos Zoulas Date: Wed Jul 25 06:12:09 2018 +0000 Bug-Debian: https://bugs.debian.org/882310 --- a/src/readelf.c +++ b/src/readelf.c @@ -352,6 +352,11 @@ off_t ph_off = off; int ph_num = num; + if (num == 0) { + if (file_printf(ms, ", no program header") == -1) + return -1; + return 0; + } if (size != xph_sizeof) { if (file_printf(ms, ", corrupted program header size") == -1) return -1; @@ -1278,6 +1283,11 @@ char name[50]; ssize_t namesize; + if (num == 0) { + if (file_printf(ms, ", no section header") == -1) + return -1; + return 0; + } if (size != xsh_sizeof) { if (file_printf(ms, ", corrupted section header size") == -1) return -1; @@ -1549,6 +1559,11 @@ ssize_t bufsize; size_t offset, align, len; + if (num == 0) { + if (file_printf(ms, ", no program header") == -1) + return -1; + return 0; + } if (size != xph_sizeof) { if (file_printf(ms, ", corrupted program header size") == -1) return -1;