This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
Re: AR archive iteration broken?
- From: Mark Wielaard <mjw at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Sun, 01 Nov 2009 17:25:23 +0100
- Subject: Re: AR archive iteration broken?
On Sun, 2009-11-01 at 12:29 +0100, Richard Guenther wrote:
> When iterating over AR archive members like
>
> while ((e = elf_begin (fd, ELF_C_READ, parent)) != NULL)
> {
> Elf_Arhdr *h = elf_getarhdr (e);
> fprintf (stderr, "%llu: %s\n", elf_getaroff (e), h->ar_name);
> elf_next (e);
> elf_end (e);
> }
>
> the iteration does not stop but instead the last archive member
> keeps being opened again and again and elf_getaroff keeps
> increasing.
This seems to be caused by elf_next() not marking the archive header as
unusable (like elf_rand() does) when there is no next element. The
following fixes it for me:
diff --git a/libelf/elf_next.c b/libelf/elf_next.c
index fbfb272..d73fac6 100644
--- a/libelf/elf_next.c
+++ b/libelf/elf_next.c
@@ -83,6 +83,11 @@ elf_next (elf)
/* Get the next archive header. */
ret = __libelf_next_arhdr_wrlock (parent) != 0 ? ELF_C_NULL : elf->cmd;
+ if (ret == ELF_C_NULL)
+ {
+ /* Mark the archive header as unusable. */
+ parent->state.ar.elf_ar_hdr.ar_name = NULL;
+ }
rwlock_unlock (parent->lock);
With that in place elf_begin() will see ar_name == NULL and that
__libelf_next_arhdr_wrlock() fails.
Cheers,
Mark