From 66a96a2d8162601ed99dc04c6fa6ecd6ee14a7f4 Mon Sep 17 00:00:00 2001 From: Petr Machata Date: Thu, 17 Mar 2011 10:51:58 +0100 Subject: [PATCH] dwarflint: Check that .shstrtab is sound --- dwarflint/Makefile.am | 3 ++- dwarflint/sections.cc | 21 ++++++++++++++------- dwarflint/tests/garbage-12.bz2 | Bin 0 -> 598 bytes dwarflint/tests/run-bad.sh | 8 +++++++- 4 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 dwarflint/tests/garbage-12.bz2 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 0000000000000000000000000000000000000000..a38e928e5c1c04c5de2e1d6f8b2ab6b51f857c64 GIT binary patch literal 598 zc-jG00;&B%T4*^jL0KkKS%@cht^fiBf13aQ{!4b}_kY{%62SlO-)Mk95I_JBAPB$# z=M-wxH8Pnb@lQ=dPtuQSo}*7wL(~~G00*c5004PUQKLbrskJmuCY1D^kTNm`fDHp6 z10XUzKxk+UlpGB-(?Ox3p^=~&0BC3pG-Ln(!eRqKB1IcYX_9(s27okr5u;*_83qW+ zlhib505BnRnWl|hcU0*EAryAojk^qnmMnd_bIs@lY_m0<9t$E2O6<*Q%Z}91GeHN~ zMwg#`N(E5Sbdr?0CKGUi9)b<-MccLAj&peE$fmG30Y8vu+9 z>aik&w9+A=b{MA8RWu|Y$Ed-uudM)NVS^JC+6zn}i_+2vV_-Icv9b8f0I~>0azYR! zA>TX{PgSaGi^3rR5f7G1(V)LoW4bi+;Anu zn*$&P8G=A@;KTfQ3IPr!@ kmoZXCGf9Fsp=$hvPz)S;1qhN{`@iDuNT&)C5d`k_z`yGW&;S4c literal 0 Hc-jL100001 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 <