This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
Re: [PATCH] readelf: prevent segfault
- From: Petr Machata <pmachata at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Tue, 22 Mar 2011 09:51:58 +0100
- Subject: Re: [PATCH] readelf: prevent segfault
Marek Polacek <mpolacek@redhat.com> writes:
> Sometimes, e.g. when malformed ELF file, the ebl_dynamic_tag_name()
> returns NULL which causes puts() to segfault immediately without
> ceremony. Fixed thusly. Tested on x86_64. Ok for trunk?
Looks OK to me, except...
> diff --git a/src/readelf.c b/src/readelf.c
> index 956d8bd..2e149b2 100644
> --- a/src/readelf.c
> +++ b/src/readelf.c
> @@ -1445,8 +1445,10 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
> printf ("%" PRId64 "\n", dyn->d_un.d_val);
> break;
>
> - case DT_PLTREL:
> - puts (ebl_dynamic_tag_name (ebl, dyn->d_un.d_val, NULL, 0));
> + case DT_PLTREL:;
...that semicolon. ^^^
> + const char *tagname = ebl_dynamic_tag_name (ebl, dyn->d_un.d_val,
> + NULL, 0);
> + puts (tagname ?: "???");
> break;
PM