[PATCH 4/4] debugedit-classify-ar: Check while elf_begin loop failed or succeeded

Mark Wielaard mark@klomp.org
Mon May 18 12:43:17 GMT 2026


The while loop calling elf_begin to check all ar members in
classify_ar_elf will end with elf == NULL when all ar members are
checked, or if there was an error reading the next ar member.
Explicitly check which case it was and set err if the loop failed.

	* tools/debugedit-classify-ar.c (classify_ar_elf): Check why
	elf == NULL at end of loop.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 tools/debugedit-classify-ar.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/tools/debugedit-classify-ar.c b/tools/debugedit-classify-ar.c
index eb6cbf702379..45c28295dc5f 100644
--- a/tools/debugedit-classify-ar.c
+++ b/tools/debugedit-classify-ar.c
@@ -160,6 +160,19 @@ classify_ar_elf (int fd, Elf *ar, const char *file)
 	break;
     }
 
+  /* Was there an error getting the next member or were we at the end?  */
+  if (!err && elf == NULL && members != 0 && cmd != ELF_C_NULL)
+    {
+      int elferr = elf_errno ();
+      if (elferr != 0)
+	{
+	  if (verbose >= 0)
+	    error (0, 0, "Couldn't read whole ar file: %s: %s",
+		   elf_errmsg (elferr), file);
+	  err = true;
+	}
+    }
+
   if (err)
     return -1;
 
-- 
2.53.0



More information about the Debugedit mailing list