[PATCH] libdwfl: Make sure there is at least one phdr

Mark Wielaard mark@klomp.org
Fri Dec 17 22:52:42 GMT 2021


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(+)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index d4eee639..8760b1ef 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -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
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index 177ad9a5..c4f79f11 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -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;
-- 
2.30.2



More information about the Elfutils-devel mailing list