From 04839d5826d21e7a603a76fddc7afed6d32ab087 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 29 Apr 2025 22:16:58 +0200 Subject: [PATCH] ar: Check elf_getahdr doesn't return NULL 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 Signed-off-by: Mark Wielaard --- src/ar.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ar.c b/src/ar.c index 9ace28b9..03118c4e 100644 --- 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 -- 2.47.2