Skip to content

Commit

Permalink
scanelf: fix hashtable overflow checks
Browse files Browse the repository at this point in the history
Make sure we use the right offset, and make sure the numbers to check
don't overflow themselves -- if nbuckets & nchains are 32-bit, and if
we multiply them by 4, we can easily overflow before we get a chance
to see if they will fit within the memory range.

Bug: https://bugs.gentoo.org/890028
Signed-off-by: Mike Frysinger <[email protected]>
  • Loading branch information
vapier committed Jan 25, 2024
1 parent 77bf161 commit c1759f9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions scanelf.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ static void scanelf_file_get_symtabs(elfobj *elf, const void **sym, const void *
Elf32_Word sym_idx; \
Elf32_Word chained; \
\
if (!VALID_RANGE(elf, offset, nbuckets * 4)) \
if (!VALID_RANGE(elf, hash_offset, nbuckets * (uint64_t)4)) \
goto corrupt_hash; \
if (!VALID_RANGE(elf, offset, nchains * 4)) \
if (!VALID_RANGE(elf, hash_offset, nchains * (uint64_t)4)) \
goto corrupt_hash; \
\
for (b = 0; b < nbuckets; ++b) { \
Expand Down

0 comments on commit c1759f9

Please sign in to comment.