33c93c3
commit 22d2d082d57a7470fadc0eae67179553f4919209
33c93c3
Author: Mark Wielaard <mark@klomp.org>
33c93c3
Date:   Thu Oct 18 23:15:48 2018 +0200
33c93c3
33c93c3
    size: Handle recursive ELF ar files.
33c93c3
    
33c93c3
    eu-size didn't handle an ELF ar file that contained an ar file itself
33c93c3
    correctly. handle_ar would recursively call itself but close the ELF
33c93c3
    file before returning. Only close the ELF file at the top-level.
33c93c3
    
33c93c3
    https://sourceware.org/bugzilla/show_bug.cgi?id=23787
33c93c3
    
33c93c3
    Signed-off-by: Mark Wielaard <mark@klomp.org>
33c93c3
33c93c3
diff --git a/src/size.c b/src/size.c
33c93c3
index 5ff3f2a..f01fd88 100644
33c93c3
--- a/src/size.c
33c93c3
+++ b/src/size.c
33c93c3
@@ -374,8 +374,10 @@ handle_ar (int fd, Elf *elf, const char *prefix, const char *fname)
33c93c3
 	INTERNAL_ERROR (fname);
33c93c3
     }
33c93c3
 
33c93c3
-  if (unlikely (elf_end (elf) != 0))
33c93c3
-    INTERNAL_ERROR (fname);
33c93c3
+  /* Only close ELF handle if this was a "top level" ar file.  */
33c93c3
+  if (prefix == NULL)
33c93c3
+    if (unlikely (elf_end (elf) != 0))
33c93c3
+      INTERNAL_ERROR (fname);
33c93c3
 
33c93c3
   return result;
33c93c3
 }