offscn sets the result before checking the section isn't empty. It
assumes the result will be reset for the next section that matches the
given offset. But this might not be the case, for example if this was
the last section. It will then return that section (and set elf_errno)
instead of returning NULL to indicate no non-empty section matched.
* libelf/elf32_offscn.c (offscn): Move assignment to result
after empty size check.
Signed-off-by: Mark Wielaard <mark@klomp.org>
for (unsigned int i = 0; i < runp->cnt; ++i)
if (runp->data[i].shdr.ELFW(e,LIBELFBITS)->sh_offset == offset)
{
- result = &runp->data[i];
-
/* If this section is empty, the following one has the same
sh_offset. We presume the caller is looking for a nonempty
section, so keep looking if this one is empty. */
if (runp->data[i].shdr.ELFW(e,LIBELFBITS)->sh_size != 0
&& runp->data[i].shdr.ELFW(e,LIBELFBITS)->sh_type != SHT_NOBITS)
- goto out;
+ {
+ result = &runp->data[i];
+ goto out;
+ }
}
runp = runp->next;