* [PATCH] libdwfl: Make sure that ph_buffer_size has room for at least one phdr
@ 2021-12-19 19:25 Mark Wielaard
0 siblings, 0 replies; only message in thread
From: Mark Wielaard @ 2021-12-19 19:25 UTC (permalink / raw)
To: elfutils-devel; +Cc: Mark Wielaard
dwfl_segment_report_module might otherwise try to handle half a phdr
taking the other half from after the buffer.
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
libdwfl/ChangeLog | 5 +++++
libdwfl/dwfl_segment_report_module.c | 7 ++++++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index d00ce702..38e2bdaa 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,8 @@
+2021-12-08 Mark Wielaard <mark@klomp.org>
+
+ * dwfl_segment_report_module.c (dwfl_segment_report_module): Make sure
+ that ph_buffer_size has room for at least one phdr.
+
2021-12-08 Mark Wielaard <mark@klomp.org>
* dwfl_segment_report_module.c (dwfl_segment_report_module): Make
diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index 89e05103..840d6f44 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -426,7 +426,12 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
buffer, otherwise it will be the size of the new buffer that
could be read. */
if (ph_buffer_size != 0)
- xlatefrom.d_size = ph_buffer_size;
+ {
+ phnum = ph_buffer_size / phentsize;
+ if (phnum == 0)
+ goto out;
+ xlatefrom.d_size = ph_buffer_size;
+ }
xlatefrom.d_buf = ph_buffer;
--
2.30.2
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-12-19 19:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-19 19:25 [PATCH] libdwfl: Make sure that ph_buffer_size has room for at least one phdr Mark Wielaard
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).