/* 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
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);
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;
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.
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