File libdwfl-sanity-check-partial-core-file-dyn-data-read.patch of Package elfutils.8903

[PATCH] libdwfl: Sanity check partial core file dyn data read.
From: Mark Wielaard <mark at klomp dot org>
To: elfutils-devel at sourceware dot org
Cc: Mark Wielaard <mark at klomp dot org>
Date: Sun, 20 Jan 2019 23:07:32 +0100
Subject: [PATCH] libdwfl: Sanity check partial core file dyn data read.
Reference: bnc#1123685

When reading the dyn data from the core file check if we got everything,
or just part of the data.

https://sourceware.org/bugzilla/show_bug.cgi?id=24103

elfutils packaging edits:
 - changelog hunk removed from original patch to avoid conflict

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 libdwfl/ChangeLog                    | 5 +++++
 libdwfl/dwfl_segment_report_module.c | 6 ++++++
 2 files changed, 11 insertions(+)

diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c
index 0d633ffee..f6ad39b3e 100644
--- a/libdwfl/dwfl_segment_report_module.c
+++ b/libdwfl/dwfl_segment_report_module.c
@@ -783,6 +783,12 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
   if (dyn_filesz != 0 && dyn_filesz % dyn_entsize == 0
       && ! read_portion (&dyn_data, &dyn_data_size, dyn_vaddr, dyn_filesz))
     {
+      /* dyn_data_size will be zero if we got everything from the initial
+         buffer, otherwise it will be the size of the new buffer that
+         could be read.  */
+      if (dyn_data_size != 0)
+	dyn_filesz = dyn_data_size;
+
       void *dyns = malloc (dyn_filesz);
       Elf32_Dyn (*d32)[dyn_filesz / sizeof (Elf32_Dyn)] = dyns;
       Elf64_Dyn (*d64)[dyn_filesz / sizeof (Elf64_Dyn)] = dyns;
-- 
2.20.1
openSUSE Build Service is sponsored by