]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdwfl: Make sure dyn_filesz has a sane size
authorMark Wielaard <mark@klomp.org>
Sun, 19 Dec 2021 19:53:34 +0000 (20:53 +0100)
committerMark Wielaard <mark@klomp.org>
Sun, 19 Dec 2021 19:53:34 +0000 (20:53 +0100)
In dwfl_segment_report_module dyn_filesz should be able to hold at
least one Elf_Dyn element, and not be larger than possible.

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

index 38e2bdaa1611ad6db010a769019df871615f56d6..1f83576d73d175611cb3b08cb156186165daef55 100644 (file)
@@ -1,3 +1,9 @@
+2021-12-08  Mark Wielaard  <mark@klomp.org>
+
+       * dwfl_segment_report_module.c (dwfl_segment_report_module): Make sure
+       that dyn_filesz can contain at least one Elf_Dyn and isn't larger than
+       possible.
+
 2021-12-08  Mark Wielaard  <mark@klomp.org>
 
        * dwfl_segment_report_module.c (dwfl_segment_report_module): Make sure
index 840d6f44740780bed72268d182d689273dd61532..78c70795fdad4e320cbed2577de00d77f8af0602 100644 (file)
@@ -787,6 +787,9 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name,
       if (dyn_data_size != 0)
        dyn_filesz = dyn_data_size;
 
+      if ((dyn_filesz / dyn_entsize) == 0
+         || dyn_filesz > (SIZE_MAX / dyn_entsize))
+       goto out;
       void *dyns = malloc (dyn_filesz);
       Elf32_Dyn *d32 = dyns;
       Elf64_Dyn *d64 = dyns;