Subject: Only trust sizes of regular files Upstream-Author: Christos Zoulas Date: Tue Dec 9 02:46:38 2014 +0000 Origin: FILE5_20-47-g68bd843 Last-Update: 2015-01-05 (prequisite for TEMP-0000000-B67840) diff --git a/src/readelf.c b/src/readelf.c index f6b6824..fd4a19f 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -62,6 +62,7 @@ private uint64_t getu64(int, uint64_t); #define MAX_PHNUM 128 #define MAX_SHNUM 32768 +#define SIZE_UNKNOWN ((off_t)-1) private int toomany(struct magic_set *ms, const char *name, uint16_t num) @@ -332,7 +333,7 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off, } off += size; - if (xph_offset > fsize) { + if (fsize != SIZE_UNKNOWN && xph_offset > fsize) { /* Perhaps warn here */ continue; } @@ -963,7 +964,7 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num, stripped = 0; break; default: - if (xsh_offset > fsize) { + if (fsize != SIZE_UNKNOWN && xsh_offset > fsize) { /* Perhaps warn here */ continue; } @@ -1148,7 +1149,7 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off, shared_libraries = " (uses shared libs)"; break; default: - if (xph_offset > fsize) { + if (fsize != SIZE_UNKNOWN && xph_offset > fsize) { /* Maybe warn here? */ continue; } @@ -1241,7 +1242,10 @@ file_tryelf(struct magic_set *ms, int fd, const unsigned char *buf, file_badread(ms); return -1; } - fsize = st.st_size; + if (S_ISREG(st.st_mode)) + fsize = st.st_size; + else + fsize = SIZE_UNKNOWN; clazz = buf[EI_CLASS];