readelf: Fix deref-of-null in dump_archive_index()

Message ID 20240401164231.23940-1-maks.mishinFZ@gmail.com
State Rejected
Headers
Series readelf: Fix deref-of-null in dump_archive_index() |

Commit Message

Maks Mishin April 1, 2024, 4:42 p.m. UTC
  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(+)
  

Patch

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);