libelf: Rearrange size test to prevent integer overflow

Sponsored by:	The FreeBSD Foundation
This commit is contained in:
emaste 2014-12-31 01:48:23 +00:00
parent 369e66acd7
commit 713a7712a6

@ -62,7 +62,7 @@ _libelf_load_section_headers(Elf *e, void *ehdr)
#define CHECK_EHDR(E,EH) do { \
if (fsz != (EH)->e_shentsize || \
shnum > SIZE_MAX / fsz || \
shoff + fsz * shnum > e->e_rawsize) { \
fsz * shnum > e->e_rawsize - shoff) { \
LIBELF_SET_ERROR(HEADER, 0); \
return (0); \
} \