libdwfl: Make sure there is at least one phdr
Commit Message
The buffer read in needs to contain room for at least one Phdr.
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
libdwfl/ChangeLog | 4 ++++
libdwfl/link_map.c | 5 +++++
2 files changed, 9 insertions(+)
@@ -1,3 +1,7 @@
+2021-12-16 Mark Wielaard <mark@klomp.org>
+
+ * link_map.c (dwfl_link_map_report): Make sure phnum is non-zero.
+
2021-12-16 Mark Wielaard <mark@klomp.org>
* link_map.c (dwfl_link_map_report): Make sure dyn_filesz / entsize is
@@ -890,6 +890,11 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
{
nbytes = in.d_size;
phnum = nbytes / phent;
+ if (phnum == 0)
+ {
+ __libdwfl_seterrno (DWFL_E_BADELF);
+ return false;
+ }
}
void *buf = malloc (nbytes);
Elf32_Phdr (*p32)[phnum] = buf;