diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2019-03-19 02:37:47 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2019-03-19 02:37:47 +0000 |
commit | 3f94c96414ca9e1099c209e87bee0d131921006c (patch) | |
tree | 8fca04f005319791ac781b201995ad7a41b48010 /lib/libelf/elf_rand.c | |
parent | cf0274fe9f59233533a1cc96887748298971c367 (diff) |
update libelf from elftoolchain r3714 to r3717
check for overflow correctly after computing a file offset
Diffstat (limited to 'lib/libelf/elf_rand.c')
-rw-r--r-- | lib/libelf/elf_rand.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/libelf/elf_rand.c b/lib/libelf/elf_rand.c index 636808c84e3..b88e4db6bf5 100644 --- a/lib/libelf/elf_rand.c +++ b/lib/libelf/elf_rand.c @@ -30,7 +30,7 @@ #include "_libelf.h" -ELFTC_VCSID("$Id: elf_rand.c,v 1.2 2019/03/19 02:31:35 jsg Exp $"); +ELFTC_VCSID("$Id: elf_rand.c,v 1.3 2019/03/19 02:37:46 jsg Exp $"); off_t elf_rand(Elf *ar, off_t offset) @@ -38,17 +38,17 @@ elf_rand(Elf *ar, off_t offset) struct ar_hdr *arh; off_t offset_of_member; - offset_of_member = offset + (off_t) sizeof(struct ar_hdr); - if (ar == NULL || ar->e_kind != ELF_K_AR || (offset & 1) || offset < SARMAG || - offset_of_member >= ar->e_rawsize) { + offset >= ar->e_rawsize) { LIBELF_SET_ERROR(ARGUMENT, 0); return 0; } - /* Check for numeric overflow. */ - if ((uintmax_t) offset_of_member < (uintmax_t) offset) { + offset_of_member = offset + (off_t) sizeof(struct ar_hdr); + + if (offset_of_member <= 0 || /* Numeric overflow. */ + offset_of_member >= ar->e_rawsize) { LIBELF_SET_ERROR(ARGUMENT, 0); return 0; } |