This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]