summaryrefslogtreecommitdiffstats
path: root/libbacktrace
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2015-05-14 15:39:52 -0700
committerChristopher Ferris <cferris@google.com>2015-05-15 11:32:53 -0700
commiteb19e766322fb57ccde989e0e35b0ac3e28a4ac2 (patch)
tree3ccf3f82433f790005edd036bdaa710be90d7702 /libbacktrace
parentc89a1774cb483f90f58cb8912e89e58f53dbb6a5 (diff)
downloadsystem_core-eb19e766322fb57ccde989e0e35b0ac3e28a4ac2.zip
system_core-eb19e766322fb57ccde989e0e35b0ac3e28a4ac2.tar.gz
system_core-eb19e766322fb57ccde989e0e35b0ac3e28a4ac2.tar.bz2
Prevent crashes if a map cannot be created.
Under some conditions, /proc/<pid>/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)
Diffstat (limited to 'libbacktrace')
-rw-r--r--libbacktrace/Backtrace.cpp4
-rw-r--r--libbacktrace/BacktraceCurrent.cpp5
-rw-r--r--libbacktrace/UnwindPtrace.cpp5
3 files changed, 13 insertions, 1 deletions
diff --git a/libbacktrace/Backtrace.cpp b/libbacktrace/Backtrace.cpp
index 4e4003e..128bb04 100644
--- a/libbacktrace/Backtrace.cpp
+++ b/libbacktrace/Backtrace.cpp
@@ -114,7 +114,9 @@ std::string Backtrace::FormatFrameData(const backtrace_frame_data_t* frame) {
}
void Backtrace::FillInMap(uintptr_t pc, backtrace_map_t* map) {
- map_->FillIn(pc, map);
+ if (map_ != nullptr) {
+ map_->FillIn(pc, map);
+ }
}
Backtrace* Backtrace::Create(pid_t pid, pid_t tid, BacktraceMap* map) {
diff --git a/libbacktrace/BacktraceCurrent.cpp b/libbacktrace/BacktraceCurrent.cpp
index 14f04de..95cd4d1 100644
--- a/libbacktrace/BacktraceCurrent.cpp
+++ b/libbacktrace/BacktraceCurrent.cpp
@@ -65,6 +65,11 @@ size_t BacktraceCurrent::Read(uintptr_t addr, uint8_t* buffer, size_t bytes) {
}
bool BacktraceCurrent::Unwind(size_t num_ignore_frames, ucontext_t* ucontext) {
+ if (GetMap() == nullptr) {
+ // Without a map object, we can't do anything.
+ return false;
+ }
+
if (ucontext) {
return UnwindFromContext(num_ignore_frames, ucontext);
}
diff --git a/libbacktrace/UnwindPtrace.cpp b/libbacktrace/UnwindPtrace.cpp
index a7c3de5..07c2430 100644
--- a/libbacktrace/UnwindPtrace.cpp
+++ b/libbacktrace/UnwindPtrace.cpp
@@ -48,6 +48,11 @@ UnwindPtrace::~UnwindPtrace() {
}
bool UnwindPtrace::Unwind(size_t num_ignore_frames, ucontext_t* ucontext) {
+ if (GetMap() == nullptr) {
+ // Without a map object, we can't do anything.
+ return false;
+ }
+
if (ucontext) {
BACK_LOGW("Unwinding from a specified context not supported yet.");
return false;