Commit c1fa2f69 authored by Carsten Emde's avatar Carsten Emde
Browse files

Added exception handlers in the ELF analysis code to prevent premature

program termination when an executable with an invalid ELF header is
analyzed
parent 585c3bf7
......@@ -568,12 +568,22 @@ def main(argv):
# ELF file. Already load a few data structures into memory
# that will be used later on as well.
openedelffile = open(fullfilename, 'rb')
elffilerepresentation = elftools.elf.elffile.ELFFile(openedelffile)
try:
elffilerepresentation = elftools.elf.elffile.ELFFile(openedelffile)
except:
print("Warning: Error occurred when analyzing ELF header of", fullfilename)
openedelffile.close()
continue
elfheader = elffilerepresentation.header
for sec in elffilerepresentation.iter_sections():
if isinstance(sec, elftools.elf.dynamic.DynamicSection):
dynamicelf = True
break
try:
for sec in elffilerepresentation.iter_sections():
if isinstance(sec, elftools.elf.dynamic.DynamicSection):
dynamicelf = True
break
except:
print("Warning: Error occurred when walking through ELF header of", fullfilename)
openedelffile.close()
continue
# statically linked binary, or not a regular ELF file,
# not interesting for now
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment