Hi Aaron,

On Fri, Nov 20, 2026 at 05:05:28PM -0500, Aaron Merey wrote:
> On Thu, Nov 19, 2026 at 7:46 PM Mark Wielaard <[email protected]> wrote:
> > diff --git a/libelf/elf_newscn.c b/libelf/elf_newscn.c
> > index fbb897153ea3..dc1fca70be17 100644
> > --- a/libelf/elf_newscn.c
> > +++ b/libelf/elf_newscn.c
> > @@ -128,8 +128,18 @@ elf_newscn (Elf *elf)
> >        newp->max = elf->state.elf.scnincr;
> >
> >        /* Remember the index for the first section in this block.  */
> > -      newp->data[0].index
> > -       = 1 + elf->state.elf.scns_last->data[elf->state.elf.scns_last->max 
> > - 1].index;
> > +      size_t last_max = elf->state.elf.scns_last->max;
> > +      if (last_max == 0)
> > +       {
> > +         /* The last block was empty, so this is the first section
> > +            (section zero).  */
> > +         newp->data[0].index = 0;
> 
> This fixes the bad index for elf descriptors with no sections. But now
> for this case elf_newscn returns the SHT_NULL section 0 which I don't
> think is intended. elf_newscn should instead create section 0 and
> section 1, then return section 1.

O, good catch. We should set first = true here. I'll double check the
retry logic works then to get the "real" first section and add a
testcase to make sure it really works.

Thanks,

Mark

> > +       }
> > +      else
> > +       {
> > +         size_t index = elf->state.elf.scns_last->data[last_max - 1].index;
> > +         newp->data[0].index = index + 1;
> > +       }
> >
> >        /* Enqueue the new list element.  */
> >        elf->state.elf.scns_last = elf->state.elf.scns_last->next = newp;
> > --
> > 2.56.1
> >
> 

Reply via email to