]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
ar: Check elf_getahdr doesn't return NULL
authorMark Wielaard <mark@klomp.org>
Tue, 29 Apr 2025 20:16:58 +0000 (22:16 +0200)
committerMark Wielaard <mark@klomp.org>
Tue, 29 Apr 2025 20:16:58 +0000 (22:16 +0200)
When elf_getahdr returns NULL we shouldn't even try to handle the ar
header, but immediately go to the next entry.

* src/ar.c (do_oper_extract): If elf_getahdr goto next.
(do_oper_delete): Likewise.
(do_oper_insert): Likewise.

Suggested-by: Anton Moryakov <ant.v.moryakov@gmail.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ar.c

index 9ace28b918d38e19caec3f4d4d99d9e46911741e..03118c4eadbe6fb2c1096c711de701c0e475f2ab 100644 (file)
--- a/src/ar.c
+++ b/src/ar.c
@@ -498,6 +498,8 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc,
   while ((subelf = elf_begin (fd, cmd, elf)) != NULL)
     {
       Elf_Arhdr *arhdr = elf_getarhdr (subelf);
+      if (arhdr == NULL)
+       goto next;
 
       if (strcmp (arhdr->ar_name, "/") == 0)
        {
@@ -943,6 +945,8 @@ do_oper_delete (const char *arfname, char **argv, int argc,
   while ((subelf = elf_begin (fd, cmd, elf)) != NULL)
     {
       Elf_Arhdr *arhdr = elf_getarhdr (subelf);
+      if (arhdr == NULL)
+       goto next;
 
       /* Ignore the symbol table and the long file name table here.  */
       if (strcmp (arhdr->ar_name, "/") == 0
@@ -1152,6 +1156,8 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc,
   while ((subelf = elf_begin (fd, cmd, elf)) != NULL)
     {
       Elf_Arhdr *arhdr = elf_getarhdr (subelf);
+      if (arhdr == NULL)
+       goto next;
 
       /* Ignore the symbol table and the long file name table here.  */
       if (strcmp (arhdr->ar_name, "/") == 0