From: Petr Machata Date: Thu, 17 Mar 2011 09:51:58 +0000 (+0100) Subject: dwarflint: Check that .shstrtab is sound X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=66a96a2d8162601ed99dc04c6fa6ecd6ee14a7f4;p=thirdparty%2Felfutils.git dwarflint: Check that .shstrtab is sound --- diff --git a/dwarflint/Makefile.am b/dwarflint/Makefile.am index 7c0a9b2f9..3da11ac0f 100644 --- a/dwarflint/Makefile.am +++ b/dwarflint/Makefile.am @@ -130,7 +130,8 @@ EXTRA_DIST = $(EXTRA_TESTS) \ tests/garbage-8.bz2 \ tests/garbage-9.bz2 \ tests/garbage-10.bz2 \ - tests/garbage-11.bz2 + tests/garbage-11.bz2 \ + tests/garbage-12.bz2 installed_TESTS_ENVIRONMENT = libdir=$(DESTDIR)$(libdir) \ bindir=$(DESTDIR)$(bindir) \ diff --git a/dwarflint/sections.cc b/dwarflint/sections.cc index add26b894..d5736c4be 100644 --- a/dwarflint/sections.cc +++ b/dwarflint/sections.cc @@ -1,5 +1,5 @@ /* Low-level section handling. - Copyright (C) 2009, 2010 Red Hat, Inc. + Copyright (C) 2009, 2010, 2011 Red Hat, Inc. This file is part of Red Hat elfutils. Red Hat elfutils is free software; you can redistribute it and/or modify @@ -252,6 +252,17 @@ namespace bool check_rel = true; + /* Try to obtain .shstrtab, which we will need in following. If + we fail, elf is broken. */ + Elf_Scn *shstrscn = elf_getscn (elf, file->ehdr.e_shstrndx); + if (shstrscn == NULL || elf_rawdata (shstrscn, NULL) == NULL) + { + invalid_elf: + wr_error () << "Broken ELF: " << elf_errmsg (-1) << "." + << std::endl; + goto close_and_out; + } + for (Elf_Scn *scn = NULL; (scn = elf_nextscn (elf, scn)); ) { REALLOC (file, sec); @@ -260,15 +271,11 @@ namespace GElf_Shdr *shdr = gelf_getshdr (scn, &cursec->shdr); if (shdr == NULL) - { - invalid_elf: - wr_error () << "Broken ELF: " << elf_errmsg (-1) << "." - << std::endl; - goto close_and_out; - } + goto invalid_elf; const char *scnname = elf_strptr (elf, file->ehdr.e_shstrndx, shdr->sh_name); + // Validate the section name if (scnname == NULL) goto invalid_elf; diff --git a/dwarflint/tests/garbage-12.bz2 b/dwarflint/tests/garbage-12.bz2 new file mode 100644 index 000000000..a38e928e5 Binary files /dev/null and b/dwarflint/tests/garbage-12.bz2 differ diff --git a/dwarflint/tests/run-bad.sh b/dwarflint/tests/run-bad.sh index 46678f0f7..41c56a5f1 100755 --- a/dwarflint/tests/run-bad.sh +++ b/dwarflint/tests/run-bad.sh @@ -30,7 +30,7 @@ srcdir=$srcdir/tests testfiles hello.bad-1 hello.bad-3 empty-1 \ garbage-1 garbage-2 garbage-3 garbage-4 \ garbage-5 garbage-6 garbage-7 garbage-8 \ - garbage-9 garbage-10 garbage-11 + garbage-9 garbage-10 garbage-11 garbage-12 testrun_compare ./dwarflint hello.bad-1 <) error: .debug_line: table 0: header claims that it has a size of 542, but in fact it has a size of 30. error: .debug_info: DIE 0xb (abbr. attribute 0xa): unresolved reference to .debug_line table 0x0. EOF + +testrun_compare ./dwarflint garbage-12 <