]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Check that the name of relocated section is valid
authorPetr Machata <pmachata@redhat.com>
Mon, 7 Mar 2011 14:57:38 +0000 (15:57 +0100)
committerPetr Machata <pmachata@redhat.com>
Mon, 7 Mar 2011 14:57:38 +0000 (15:57 +0100)
dwarflint/sections.cc
dwarflint/tests/garbage-1.bz2 [new file with mode: 0644]
dwarflint/tests/run-bad.sh

index b1fb2a6723921bbfb746b69f27be89bfc8538db0..add26b894f04e382d62b465cad7e485c4e92af07 100644 (file)
@@ -262,7 +262,8 @@ namespace
        if (shdr == NULL)
          {
          invalid_elf:
-           wr_error () << "Broken ELF." << std::endl;
+           wr_error () << "Broken ELF: " << elf_errmsg (-1) << "."
+                       << std::endl;
            goto close_and_out;
          }
 
@@ -318,9 +319,10 @@ namespace
            const char *relocated_scnname
              = elf_strptr (elf, file->ehdr.e_shstrndx,
                            relocated_shdr->sh_name);
+           if (unlikely (relocated_scnname == NULL))
+             goto invalid_elf;
 
            secentry *relocated = secinfo.get (relocated_scnname);
-
            if (relocated != NULL)
              {
                if (relocated->reldata != NULL)
diff --git a/dwarflint/tests/garbage-1.bz2 b/dwarflint/tests/garbage-1.bz2
new file mode 100644 (file)
index 0000000..de1b26d
Binary files /dev/null and b/dwarflint/tests/garbage-1.bz2 differ
index d67554fbda9cde9949503a7901ad58d40dc08a41..5dd6495660836b488cfd6d28830849ea951b8c3a 100755 (executable)
@@ -27,7 +27,7 @@
 
 srcdir=$srcdir/tests
 
-testfiles hello.bad-1 hello.bad-3
+testfiles hello.bad-1 hello.bad-3 garbage-1
 
 testrun_compare ./dwarflint hello.bad-1 <<EOF
 error: .debug_info: DIE 0x83: abbrev section at 0x0 doesn't contain code 83.
@@ -40,3 +40,9 @@ error: .debug_info: DIE 0x9e: toplevel DIE chain contains more than one DIE.
 error: .debug_info: DIE 0xa4: toplevel DIE chain contains more than one DIE.
 error: .debug_info: DIE 0xab: toplevel DIE chain contains more than one DIE.
 EOF
+
+testrun_compare ./dwarflint garbage-1 <<EOF
+error: Broken ELF: offset out of range.
+error: .debug_abbrev: data not found.
+error: .debug_info: data not found.
+EOF