[PATCH] objdump.c: potential NULL pointer dereference in handle_ar
ant.v.moryakov@gmail.com
ant.v.moryakov@gmail.com
Wed Oct 23 11:14:14 GMT 2024
From: AntonMoryakov <ant.v.moryakov@gmail.com>
- Added a check to ensure `arhdr` is not NULL before using it in `strcmp` to avoid segmentation fault.
- This resolves the issue where the pointer returned from `elf_getarhdr` may be NULL and causes a crash when dereferenced.
---
src/objdump.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/objdump.c b/src/objdump.c
index 1b38da23..33b6fec5 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.34.1
More information about the Elfutils-devel
mailing list