Issue #119: readelf - don't do hex/string dumps for SHT_NOBITS sections
authorEli Bendersky <eliben@gmail.com>
Sat, 15 Oct 2016 21:08:50 +0000 (14:08 -0700)
committerEli Bendersky <eliben@gmail.com>
Sat, 15 Oct 2016 21:08:50 +0000 (14:08 -0700)
scripts/readelf.py

index 60c9c3e7eb13639bc24975a1f8cd72303a916b97..2a8b31e2cdffbd846f104063cc0002a37a5bae03 100755 (executable)
@@ -304,7 +304,6 @@ class ReadElf(object):
                 self._emitline('   Num:    Value          Size Type    Bind   Vis      Ndx Name')
 
             for nsym, symbol in enumerate(section.iter_symbols()):
-
                 version_info = ''
                 # readelf doesn't display version info for Solaris versioning
                 if (section['sh_type'] == 'SHT_DYNSYM' and
@@ -572,6 +571,10 @@ class ReadElf(object):
             self._emitline("Section '%s' does not exist in the file!" % (
                 section_spec))
             return
+        if section['sh_type'] == 'SHT_NOBITS':
+            self._emitline("\nSection '%s' has no data to dump." % (
+                section_spec))
+            return
 
         self._emitline("\nHex dump of section '%s':" % section.name)
         self._note_relocs_for_section(section)
@@ -615,6 +618,10 @@ class ReadElf(object):
             self._emitline("Section '%s' does not exist in the file!" % (
                 section_spec))
             return
+        if section['sh_type'] == 'SHT_NOBITS':
+            self._emitline("\nSection '%s' has no data to dump." % (
+                section_spec))
+            return
 
         self._emitline("\nString dump of section '%s':" % section.name)