[PATCH] ld/pdb: Zero-initialize symbol arrays in handle_debugs_section

Oleg Tolmatcev oleg.tolmatcev@gmail.com
Fri Nov 6 11:16:46 GMT 2026


пт, 6 нояб. 2026 г. в 11:35, Jan Beulich <jbeulich@suse.com>:
>
> On 02.11.2026 23:59, Oleg Tolmatcev wrote:
> > handle_debugs_section only fills in symbols and sectlist for primary
> > symbols with a positive section number, so a relocation in a malformed
> > object referring to any other symbol read uninitialized memory.
> > Allocate both arrays with xcalloc; the relocate_section routines skip
> > relocations against a NULL section.
>
> This primarily explains why sectlist wants clearing up front. And indeed
> for that you address a pre-existing issue. For symbols[], otoh, prior to
> "ld/pdb: Skip auxiliary symbol entries in handle_debugs_section" all
> elements of the array are initialized. Hence that clearing (to play safe)
> imo wants moving to that patch.
>
> > --- a/ld/pdb.c
> > +++ b/ld/pdb.c
> > @@ -1948,8 +1948,8 @@ handle_debugs_section (asection *s, bfd *mod, struct string_table *strings,
> >
> >        relocs = bfd_coff_read_internal_relocs (mod, s, false, NULL, true, NULL);
> >
> > -      symbols = xmalloc (sizeof (struct internal_syment) * syment_count);
> > -      sectlist = xmalloc (sizeof (asection *) * syment_count);
> > +      symbols = xcalloc (syment_count, sizeof (struct internal_syment));
> > +      sectlist = xcalloc (syment_count, sizeof (asection *));
>
> While making these changes it would be nice if the sizeof(<type>) were
> also changed to the more robust sizeof(<expr>) (making sure a type change
> of the variables stored into is also reflected in a size change).
>
> I can make these changes ahead of committing, provided you agree.
>
> Jan

I do agree of course, thanks.

Oleg


More information about the Binutils mailing list