From eb19e766322fb57ccde989e0e35b0ac3e28a4ac2 Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Thu, 14 May 2015 15:39:52 -0700 Subject: Prevent crashes if a map cannot be created. Under some conditions, /proc//maps might return nothing. If we try and unwind in this case, we'll crash. Check this case and fail the unwind. Add checks that no other functions try and use map_ without checking for nullptr. Add logging when an unwind fails so it's clear what happened. Bug: 21162746 Change-Id: I56ce51dda0cfc9db20475a441f118108196aa07c (cherry picked from commit 30c942cf1024bf791c28ab9b67a1f752de72248c) --- debuggerd/backtrace.cpp | 6 ++++++ debuggerd/tombstone.cpp | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'debuggerd') diff --git a/debuggerd/backtrace.cpp b/debuggerd/backtrace.cpp index c2a1dbc..79ee4e5 100644 --- a/debuggerd/backtrace.cpp +++ b/debuggerd/backtrace.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#define LOG_TAG "DEBUG" + #include #include #include @@ -27,6 +29,8 @@ #include #include + +#include #include #include "backtrace.h" @@ -95,6 +99,8 @@ static void dump_thread( UniquePtr backtrace(Backtrace::Create(tid, BACKTRACE_CURRENT_THREAD)); if (backtrace->Unwind(0)) { dump_backtrace_to_log(backtrace.get(), log, " "); + } else { + ALOGE("Unwind failed: tid = %d", tid); } if (!attached && ptrace(PTRACE_DETACH, tid, 0, 0) != 0) { diff --git a/debuggerd/tombstone.cpp b/debuggerd/tombstone.cpp index b7e6b17..4c804ee 100644 --- a/debuggerd/tombstone.cpp +++ b/debuggerd/tombstone.cpp @@ -448,6 +448,8 @@ static bool dump_sibling_thread_report( UniquePtr backtrace(Backtrace::Create(pid, new_tid, map)); if (backtrace->Unwind(0)) { dump_backtrace_and_stack(backtrace.get(), log); + } else { + ALOGE("Unwind of sibling failed: pid = %d, tid = %d", pid, new_tid); } log->current_tid = log->crashed_tid; @@ -650,9 +652,13 @@ static bool dump_crash(log_t* log, pid_t pid, pid_t tid, int signal, int si_code dump_registers(log, tid); if (backtrace->Unwind(0)) { dump_backtrace_and_stack(backtrace.get(), log); + } else { + ALOGE("Unwind failed: pid = %d, tid = %d", pid, tid); } dump_memory_and_code(log, tid); - dump_all_maps(backtrace.get(), map.get(), log, tid); + if (map.get() != nullptr) { + dump_all_maps(backtrace.get(), map.get(), log, tid); + } if (want_logs) { dump_logs(log, pid, 5); -- cgit v1.1