This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] ELF/BFD: Hold the number of internal static relocs in `->reloc_count'
- From: "Maciej W. Rozycki" <macro at imgtec dot com>
- To: Alan Modra <amodra at gmail dot com>
- Cc: "Joseph S. Myers" <joseph at codesourcery dot com>, "Jose E. Marchesi" <jose dot marchesi at oracle dot com>, <binutils at sourceware dot org>
- Date: Fri, 2 Jun 2017 01:23:40 +0100
- Subject: Re: [PATCH] ELF/BFD: Hold the number of internal static relocs in `->reloc_count'
- Authentication-results: sourceware.org; auth=none
- References: <alpine.DEB.2.00.1705301242420.2590@tp.orcam.me.uk> <20170602000254.GP8842@bubble.grove.modra.org>
On Fri, 2 Jun 2017, Alan Modra wrote:
> > --- binutils.orig/bfd/elflink.c 2017-06-01 21:40:51.679023736 +0100
> > +++ binutils/bfd/elflink.c 2017-06-01 21:44:09.454957776 +0100
> > @@ -2450,8 +2450,7 @@ _bfd_elf_link_read_relocs (bfd *abfd,
> > {
> > bfd_size_type size;
> >
> > - size = o->reloc_count;
> > - size *= bed->s->int_rels_per_ext_rel * sizeof (Elf_Internal_Rela);
> > + size = o->reloc_count * sizeof (Elf_Internal_Rela);
>
> Please cast o->reloc_count to bfd_size_type so that we continue to
> catch some cases of overflow here.
I'll go with:
size = o->reloc_count;
size *= sizeof (Elf_Internal_Rela);
then if you don't mind. I find explicit casts worsen code readability.
Maciej