This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
Re: [patch 2/3] Fix abort() on missing section headers
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Sun, 02 Mar 2014 22:35:40 +0100
- Subject: Re: [patch 2/3] Fix abort() on missing section headers
On Tue, 25 Feb 2014 23:30:55 +0100, Mark Wielaard wrote:
> We certainly shouldn't abort on bad data!
> But do we even need to continue at this point?
>
> return result; means we will keep searching through the section table,
> which apparently is busted anyway. So I think it makes sense to cleanup
> and return NULL; instead.
>
> See how we cleanup and return NULL just below this code when elf_strptr
> fails.
Yes, I agree.
Thanks,
Jan
libdw/
2014-03-02 Jan Kratochvil <jan.kratochvil@redhat.com>
Fix abort() on missing section headers.
* dwarf_begin_elf.c (check_section): Replace abort call by goto err.
New label err to return NULL.
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c
index 6cf3aa1..79daeac 100644
--- a/libdw/dwarf_begin_elf.c
+++ b/libdw/dwarf_begin_elf.c
@@ -187,9 +187,9 @@ check_section (Dwarf *result, GElf_Ehdr *ehdr, Elf_Scn *scn, bool inscngrp)
/* Get the section header data. */
shdr = gelf_getshdr (scn, &shdr_mem);
if (shdr == NULL)
- /* This should never happen. If it does something is
- wrong in the libelf library. */
- abort ();
+ /* We may read /proc/PID/mem with only program headers mapped and section
+ headers out of the mapped pages. */
+ goto err;
/* Ignore any SHT_NOBITS sections. Debugging sections should not
have been stripped, but in case of a corrupt file we won't try
@@ -215,6 +215,7 @@ check_section (Dwarf *result, GElf_Ehdr *ehdr, Elf_Scn *scn, bool inscngrp)
{
/* The section name must be valid. Otherwise is the ELF file
invalid. */
+ err:
__libdw_free_zdata (result);
Dwarf_Sig8_Hash_free (&result->sig8_hash);
__libdw_seterrno (DWARF_E_INVALID_ELF);