This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH, COMMITTED]: Fix seg fault in elf32.em:_after_open
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Pedro Alves <pedro at codesourcery dot com>
- Cc: binutils at sourceware dot org, Nick Clifton <nickc at redhat dot com>
- Date: Fri, 20 Aug 2010 09:28:21 -0700
- Subject: Re: [PATCH, COMMITTED]: Fix seg fault in elf32.em:_after_open
- References: <m3lj815nxt.fsf@redhat.com> <201008201616.50214.pedro@codesourcery.com>
On Fri, Aug 20, 2010 at 8:16 AM, Pedro Alves <pedro@codesourcery.com> wrote:
> On Friday 20 August 2010 16:00:30, Nick Clifton wrote:
>> ? Whilst working on another bug I came across a seg-fault in the
>> ? _after_open() function in elf32.em. ?If the target is not an ELF
>> ? binary then get_elf_backend_data will return NULL, but the code was
>> ? not checking for this. ?Fixed by applying the following patch.
>
> (...)
>
>> ? ? ? ? ? bed = get_elf_backend_data (abfd);
>> ! ? ? ? ? if (bed == NULL)
>> ! ? ? ? ? ? s = NULL;
>> ! ? ? ? ? else
>> ! ? ? ? ? ? s = bfd_make_section_with_flags (abfd, ".eh_frame_hdr",
>> ! ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?bed->dynamic_sec_flags
>> ! ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| SEC_READONLY);
>
> Is it valid to call get_elf_backend_data on a non-elf bfd at all?
>
> #define get_elf_backend_data(abfd) \
> ? xvec_get_elf_backend_data ((abfd)->xvec)
>
> #define bfd_mach_o_get_backend_data(abfd) \
> ?((bfd_mach_o_backend_data*)(abfd)->xvec->backend_data)
>
> .#define coff_backend_info(abfd) \
> . ?((bfd_coff_backend_data *) (abfd)->xvec->backend_data)
>
> It appears that for other flavours, it may happen to return
> something undefined.
>
> Shouldn't that check be something like
> bfd_get_flavour (abfd) != bfd_target_elf_flavour instead?
>
I agree. The patch doesn't look right to me. Nick, if you can
provide a testcase, I will look into it.
Thanks.
--
H.J.