]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdwfl: Make sure that ph_buffer_size has room for at least one phdr
authorMark Wielaard <mark@klomp.org>
Sun, 19 Dec 2021 19:23:30 +0000 (20:23 +0100)
committerMark Wielaard <mark@klomp.org>
Sun, 19 Dec 2021 19:23:30 +0000 (20:23 +0100)
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
libdwfl/dwfl_segment_report_module.c

index d00ce7020b4bda10463ebf1cc697ffb759a325ae..38e2bdaa1611ad6db010a769019df871615f56d6 100644 (file)
@@ -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
index 89e05103f28b405ffab6cfe190d0d7b9908de2af..840d6f44740780bed72268d182d689273dd61532 100644 (file)
@@ -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;