]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdwfl: Make sure there is at least one phdr
authorMark Wielaard <mark@klomp.org>
Fri, 17 Dec 2021 22:51:35 +0000 (23:51 +0100)
committerMark Wielaard <mark@klomp.org>
Sat, 18 Dec 2021 01:23:44 +0000 (02:23 +0100)
The buffer read in needs to contain room for at least one Phdr.

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

index d4eee6393ea98a0ef3640bdc3929ebeb236b7465..8760b1ef883c54064311652af062accedcc4c60e 100644 (file)
@@ -1,3 +1,7 @@
+2021-12-16  Mark Wielaard  <mark@klomp.org>
+
+       * link_map.c (dwfl_link_map_report): Make sure phnum is non-zero.
+
 2021-12-16  Mark Wielaard  <mark@klomp.org>
 
        * link_map.c (dwfl_link_map_report): Make sure dyn_filesz / entsize is
index 177ad9a5fc37ac23c73577099539bf5da3a637ad..c4f79f11229a9b1c8a80845095356e88b3531687 100644 (file)
@@ -890,6 +890,11 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
                {
                  nbytes = in.d_size;
                  phnum = nbytes / phent;
+                 if (phnum == 0)
+                   {
+                     __libdwfl_seterrno (DWFL_E_BADELF);
+                     return false;
+                   }
                }
              void *buf = malloc (nbytes);
              Elf32_Phdr (*p32)[phnum] = buf;