Skip to content

Commit

Permalink
Section type check on dynamic to strtab link (#573)
Browse files Browse the repository at this point in the history
* Section type check on dynamic to strtab link

* Multiple expected types
  • Loading branch information
sevaa authored Oct 22, 2024
1 parent e4b8ad9 commit b41f577
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion elftools/elf/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class DynamicSection(Section, Dynamic):
"""
def __init__(self, header, name, elffile):
Section.__init__(self, header, name, elffile)
stringtable = elffile.get_section(header['sh_link'])
stringtable = elffile.get_section(header['sh_link'], ('SHT_STRTAB', 'SHT_NOBITS'))
Dynamic.__init__(self, self.stream, self.elffile, stringtable,
self['sh_offset'], self['sh_type'] == 'SHT_NOBITS')

Expand Down
4 changes: 3 additions & 1 deletion elftools/elf/elffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,13 @@ def num_sections(self):
return self._get_section_header(0)['sh_size']
return self['e_shnum']

def get_section(self, n):
def get_section(self, n, type=None):
""" Get the section at index #n from the file (Section object or a
subclass)
"""
section_header = self._get_section_header(n)
if type and section_header.sh_type not in type:
raise ELFError("Unexpected section type %s, expected %s" % (section_header['sh_type'], type))
return self._make_section(section_header)

def _get_linked_symtab_section(self, n):
Expand Down

0 comments on commit b41f577

Please sign in to comment.