gwcheck

Check .gnu.warning.* sections in ELF object files
Log | Files | Refs | README | LICENSE

commit 788e03b6e9e718dd1b42a05ce0a0b4a0f170135c
parent 98559ae3a62c4cab6e6f784c375ce237ba133b53
Author: Frederic Cambus <fred@statdns.com>
Date:   Thu,  4 Nov 2021 16:34:14 +0100

Add error handling and exit if input file is not a valid ELF object.

Diffstat:
Mgwcheck | 15++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/gwcheck b/gwcheck @@ -16,15 +16,20 @@ import sys from elftools.elf.elffile import ELFFile +from elftools.common.exceptions import ELFError def main(): with open(sys.argv[1], "rb") as f: - for section in ELFFile(f).iter_sections(): - if section["sh_type"] == "SHT_PROGBITS": - if section.name.startswith(".gnu.warning"): - print(section.name + ":") - print("\t" + section.data().decode("utf-8").rstrip("\0")) + try: + for section in ELFFile(f).iter_sections(): + if section["sh_type"] == "SHT_PROGBITS": + if section.name.startswith(".gnu.warning"): + print(section.name + ":") + print("\t" + section.data().decode("utf-8").rstrip("\0")) + except ELFError as ex: + sys.stderr.write("Error: %s\n" % ex) + sys.exit(1) if __name__ == "__main__":