public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] readelf: Fix deref-of-null in dump_archive_index()
@ 2024-04-01 16:42 Maks Mishin
  0 siblings, 0 replies; only message in thread
From: Maks Mishin @ 2024-04-01 16:42 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Maks Mishin

Pointer, returned from function 'elf_getarhdr' ar readelf.c:13551,
may be NULL and is dereferenced at readelf.c:13553.

Found by RASU JCS.

Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
---
 src/readelf.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/readelf.c b/src/readelf.c
index 0e931184..a650c0b9 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -13549,6 +13549,12 @@ dump_archive_index (Elf *elf, const char *fname)
 			  as_off, fname, elf_errmsg (-1));
 
 	  const Elf_Arhdr *h = elf_getarhdr (subelf);
+	  if (h == NULL)
+	{
+	  printf ("cannot get archive header in '%s': %s\n",
+	    fname, elf_errmsg (-1));
+	  return;
+	}
 
 	  printf (_("Archive member '%s' contains:\n"), h->ar_name);
 
-- 
2.30.2


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-01 16:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-01 16:42 [PATCH] readelf: Fix deref-of-null in dump_archive_index() Maks Mishin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).