This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]