Skip to content

Commit

Permalink
Additional elf parsing check to avoid integer overflow. (#2131)
Browse files Browse the repository at this point in the history
  • Loading branch information
shanehuntley authored Jan 13, 2025
1 parent d3eae32 commit 5ff67fc
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions libyara/modules/elf/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,20 +791,24 @@ static const char* str_table_entry(
\
if (yr_##bo##32toh(segment->type) == ELF_PT_DYNAMIC) \
{ \
elf##bits##_dyn_t* dyn = \
(elf##bits##_dyn_t*) (elf_raw + yr_##bo##bits##toh(segment->offset)); \
\
for (j = 0; IS_VALID_PTR(elf, elf_size, dyn); dyn++, j++) \
j = 0; \
if (yr_##bo##bits##toh(segment->offset) < elf_size) \
{ \
yr_set_integer( \
yr_##bo##bits##toh(dyn->tag), elf_obj, "dynamic[%i].type", j); \
yr_set_integer( \
yr_##bo##bits##toh(dyn->val), elf_obj, "dynamic[%i].val", j); \
elf##bits##_dyn_t* dyn = \
(elf##bits##_dyn_t*) (elf_raw + yr_##bo##bits##toh(segment->offset)); \
\
if (dyn->tag == ELF_DT_NULL) \
for (j = 0; IS_VALID_PTR(elf, elf_size, dyn); dyn++, j++) \
{ \
j++; \
break; \
yr_set_integer( \
yr_##bo##bits##toh(dyn->tag), elf_obj, "dynamic[%i].type", j); \
yr_set_integer( \
yr_##bo##bits##toh(dyn->val), elf_obj, "dynamic[%i].val", j); \
\
if (dyn->tag == ELF_DT_NULL) \
{ \
j++; \
break; \
} \
} \
} \
yr_set_integer(j, elf_obj, "dynamic_section_entries"); \
Expand Down

0 comments on commit 5ff67fc

Please sign in to comment.