summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Machata <[email protected]>2011-03-17 10:51:58 +0100
committerPetr Machata <[email protected]>2011-03-17 10:51:58 +0100
commit66a96a2d8162601ed99dc04c6fa6ecd6ee14a7f4 (patch)
treeab412355c251913500ec3d4a3116dd90ea99e03d
parentbe15b856ba63221aa0fc2fc05eb0f3dd36963670 (diff)
dwarflint: Check that .shstrtab is sound
-rw-r--r--dwarflint/Makefile.am3
-rw-r--r--dwarflint/sections.cc21
-rw-r--r--dwarflint/tests/garbage-12.bz2bin0 -> 598 bytes
-rwxr-xr-xdwarflint/tests/run-bad.sh8
4 files changed, 23 insertions, 9 deletions
diff --git a/dwarflint/Makefile.am b/dwarflint/Makefile.am
index 7c0a9b2f..3da11ac0 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 add26b89..d5736c4b 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 00000000..a38e928e
--- /dev/null
+++ b/dwarflint/tests/garbage-12.bz2
Binary files differ
diff --git a/dwarflint/tests/run-bad.sh b/dwarflint/tests/run-bad.sh
index 46678f0f..41c56a5f 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 <<EOF
error: .debug_info: DIE 0x83: abbrev section at 0x0 doesn't contain code 83.
@@ -116,3 +116,9 @@ error: .rela.debug_info: offset 0x3600: invalid relocation 256 (<INVALID RELOC>)
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 <<EOF
+error: Broken ELF: invalid section header.
+error: .debug_abbrev: data not found.
+error: .debug_info: data not found.
+EOF