Fix parsing string table (#134)
authorgcmoreira <gmoreira@gmail.com>
Thu, 2 Feb 2017 13:47:30 +0000 (00:47 +1100)
committerEli Bendersky <eliben@users.noreply.github.com>
Thu, 2 Feb 2017 13:47:30 +0000 (05:47 -0800)
If for any reason parse_cstring_from_stream() cannot get a string in the given offset, it'll return None causing the following line raises an exception when it tries to get the decoded ascii string from the None object.

elftools/elf/sections.py

index 99550ac365578e67d5b4bde0493a02dde511ee7b..1bc17157c3f58dc583f56d451d65fae011a0b898 100644 (file)
@@ -71,7 +71,7 @@ class StringTableSection(Section):
         """
         table_offset = self['sh_offset']
         s = parse_cstring_from_stream(self.stream, table_offset + offset)
-        return s.decode('ascii')
+        return s.decode('ascii') if s else ''
 
 
 class SymbolTableSection(Section):