Hi Anton, I changed the indention from using spaces to tabs and rewrote the subject line to better explain the change.
Pushed as attached. Thanks, Mark
>From 6c76ce7331e82a6fc6c2004e8e6ae51ca91f51d7 Mon Sep 17 00:00:00 2001 From: Anton Moryakov <ant.v.morya...@gmail.com> Date: Wed, 5 Feb 2025 00:50:23 +0300 Subject: [PATCH] objdump: Handle elf_getarhdr returning NULL in handle_ar Report of the static analyzer: Pointer, returned from function 'elf_getarhdr' at objdump.c:314, may be NULL and is dereferenced at objdump.c:317. (CWE-476, CWE-690) Corrections explained: When processing archive elements, the code could dereference a NULL pointer if 'elf_getarhdr' returns NULL. This patch adds a check to ensure 'arhdr' is not NULL before using it. The fix ensures that the function safely handles cases where 'elf_getarhdr' fails, avoiding potential crashes. Triggers found by static analyzer Svace. Signed-off-by: Anton Moryakov <ant.v.morya...@gmail.com> --- src/objdump.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/objdump.c b/src/objdump.c index 1b38da23266d..1f72eab8d469 100644 --- a/src/objdump.c +++ b/src/objdump.c @@ -313,7 +313,8 @@ handle_ar (int fd, Elf *elf, const char *prefix, const char *fname, Elf_Arhdr *arhdr = elf_getarhdr (subelf); /* Skip over the index entries. */ - if (strcmp (arhdr->ar_name, "/") != 0 + if (arhdr != NULL + && strcmp (arhdr->ar_name, "/") != 0 && strcmp (arhdr->ar_name, "//") != 0) { if (elf_kind (subelf) == ELF_K_ELF) -- 2.48.1