]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdwfl: Make dwfl_segment_report_module aware of maximum Elf size
authorMark Wielaard <mark@klomp.org>
Fri, 17 Dec 2021 16:43:19 +0000 (17:43 +0100)
committerMark Wielaard <mark@klomp.org>
Sat, 18 Dec 2021 01:24:28 +0000 (02:24 +0100)
At the end of dwfl_segment_report_module we might try to read in
the whole contents described by a core file. To do this we first
allocate a zeroed block of memory that is as big as possible. The
core file however may describe much more loaded data than is actually
available in the Elf image. So pass the maximum size so we can
limit the amount of memory we reserve.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdwfl/ChangeLog
libdwfl/core-file.c
libdwfl/dwfl_segment_report_module.c
libdwfl/libdwflP.h

index f18a0c45701af6572ffeb85c55d7787d2b599518..6a3e041bd21ff69be90817012d7f5cae273dbc3b 100644 (file)
@@ -1,3 +1,11 @@
+2021-12-17  Mark Wielaard  <mark@klomp.org>
+
+       * libdwflP.h (dwfl_segment_report_module): Add maxread argument.
+       * core-file.c (dwfl_core_file_report): Pass elf->maximum_size to
+       dwfl_segment_report_module.
+       * dwfl_segment_report_module.c (dwfl_segment_report_module): Add
+       maxread argument. Check file_trimmed_end against maxread.
+
 2021-12-16  Mark Wielaard  <mark@klomp.org>
 
        * dwfl_segment_report_module.c (dwfl_segment_report_module): Check
index 4e4c9b3cff1a9f1f4b9b9d2ac665897a3e638a01..b04d1d18b031a62ff5f067db8ff9b8bcfa242851 100644 (file)
@@ -559,6 +559,7 @@ dwfl_core_file_report (Dwfl *dwfl, Elf *elf, const char *executable)
       int seg = dwfl_segment_report_module (dwfl, ndx, NULL,
                                            &dwfl_elf_phdr_memory_callback, elf,
                                            core_file_read_eagerly, elf,
+                                           elf->maximum_size,
                                            note_file, note_file_size,
                                            &r_debug_info);
       if (unlikely (seg < 0))
index 2263e3cc1b1907cff254493318b338e33c4cdeab..3e87d2070706275813018235c617183f4da02036 100644 (file)
@@ -294,6 +294,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
                            void *memory_callback_arg,
                            Dwfl_Module_Callback *read_eagerly,
                            void *read_eagerly_arg,
+                           size_t maxread,
                            const void *note_file, size_t note_file_size,
                            const struct r_debug_info *r_debug_info)
 {
@@ -911,8 +912,8 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
       /* The caller wants to read the whole file in right now, but hasn't
         done it for us.  Fill in a local image of the virtual file.  */
 
-      if (file_trimmed_end > SIZE_MAX)
-       goto out;
+      if (file_trimmed_end > maxread)
+       file_trimmed_end = maxread;
 
       void *contents = calloc (1, file_trimmed_end);
       if (unlikely (contents == NULL))
index 4344e356b4529ed95e38a2e6c901cdbe770b2a5f..7503a6273065b8614ffa4d75fe90514522109dbf 100644 (file)
@@ -698,6 +698,7 @@ extern int dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
                                       void *memory_callback_arg,
                                       Dwfl_Module_Callback *read_eagerly,
                                       void *read_eagerly_arg,
+                                      size_t maxread,
                                       const void *note_file,
                                       size_t note_file_size,
                                       const struct r_debug_info *r_debug_info);