libdwfl: Make sure there is at least one dynamic entry
authorMark Wielaard <mark@klomp.org>
Fri, 17 Dec 2021 21:53:13 +0000 (22:53 +0100)
committerMark Wielaard <mark@klomp.org>
Sat, 18 Dec 2021 01:23:44 +0000 (02:23 +0100)
The buffer read in needs to contain room for at least one Elf32_Dyn or
Elf64_Dyn entry.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdwfl/ChangeLog
libdwfl/link_map.c

index f849b81..d4eee63 100644 (file)
@@ -1,3 +1,8 @@
+2021-12-16  Mark Wielaard  <mark@klomp.org>
+
+       * link_map.c (dwfl_link_map_report): Make sure dyn_filesz / entsize is
+       non-zero.
+
 2021-12-08  Mark Wielaard  <mark@klomp.org>
 
        * dwfl_segment_report_module.c (dwfl_segment_report_module): Add
index 82df7b6..177ad9a 100644 (file)
@@ -1017,6 +1017,11 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
                 in.d_size. The data might have been truncated.  */
              if (dyn_filesz > in.d_size)
                dyn_filesz = in.d_size;
+             if (dyn_filesz / entsize == 0)
+               {
+                 __libdwfl_seterrno (DWFL_E_BADELF);
+                 return false;
+               }
              void *buf = malloc (dyn_filesz);
              Elf32_Dyn (*d32)[dyn_filesz / sizeof (Elf32_Dyn)] = buf;
              Elf64_Dyn (*d64)[dyn_filesz / sizeof (Elf64_Dyn)] = buf;