[COMMITTED] libdw: Call Dwarf oom_handler() when malloc fails in __libdw_alloc_tail.

Mark Wielaard mark@klomp.org
Sun Apr 26 00:34:23 GMT 2020


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     | 5 +++++
 libdw/libdw_alloc.c | 5 +++++
 2 files changed, 10 insertions(+)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 39730fbc..75fc8f06 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -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.
diff --git a/libdw/libdw_alloc.c b/libdw/libdw_alloc.c
index e0281a3d..b3e53343 100644
--- a/libdw/libdw_alloc.c
+++ b/libdw/libdw_alloc.c
@@ -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;
-- 
2.18.2



More information about the Elfutils-devel mailing list