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