]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdw: Call Dwarf oom_handler() when malloc fails in __libdw_alloc_tail.
authorMark Wielaard <mark@klomp.org>
Sat, 25 Apr 2020 23:41:27 +0000 (01:41 +0200)
committerMark Wielaard <mark@klomp.org>
Sun, 26 Apr 2020 00:33:02 +0000 (02:33 +0200)
GCC10 -fanalyzer found a possibly-NULL dereference after a failed
malloc in __libdw_alloc_tail. In this case we should call the Dwarf
oom_handler as is done in other places where an essential malloc
call fails. The oom_handler cannot return and will likely just abort.

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

index 39730fbc7238b3b4fb268697308ca4d91d61fb07..75fc8f0624538bc95187279505ee190735dcf049 100644 (file)
@@ -1,3 +1,8 @@
+2020-04-25  Mark Wielaard  <mark@klomp.org>
+
+       * libdw_alloc.c (__libdw_alloc_tail): Call Dwarf oom_handler()
+       when malloc fails.
+
 2020-04-17  Mark Wielaard  <mark@klomp.org>
 
        * dwarf_begin_elf.c (check_section): Handle .gnu.debuglto_ prefix.
index e0281a3df78681ffeab2f398bc0f90ffe22457cc..b3e53343493900c15af8cf420920d738b0d6ac1d 100644 (file)
@@ -87,6 +87,11 @@ __libdw_alloc_tail (Dwarf *dbg)
   if (result == NULL)
     {
       result = malloc (dbg->mem_default_size);
+      if (result == NULL)
+       {
+         pthread_rwlock_unlock (&dbg->mem_rwl);
+         dbg->oom_handler();
+       }
       result->size = dbg->mem_default_size
                      - offsetof (struct libdw_memblock, mem);
       result->remaining = result->size;