summaryrefslogtreecommitdiffstats
path: root/libutils
diff options
context:
space:
mode:
authorIgor Murashkin <iam@google.com>2014-08-19 11:48:52 -0700
committerIgor Murashkin <iam@google.com>2014-08-19 11:48:52 -0700
commit63fbdb6440ce5009ef0bfd3d1e1cc60b46004973 (patch)
tree5e971663e4ae8aceae392423e44aaa97d1ff74ba /libutils
parent342a2264b96ab05dc8fdbfa8bbe354ce2f4b06ca (diff)
downloadsystem_core-63fbdb6440ce5009ef0bfd3d1e1cc60b46004973.zip
system_core-63fbdb6440ce5009ef0bfd3d1e1cc60b46004973.tar.gz
system_core-63fbdb6440ce5009ef0bfd3d1e1cc60b46004973.tar.bz2
libutils: Don't segfault ProcessCallStack when getting thread name fails
There's an inherent race in trying to read out the thread name from the system and the thread closing out on its own (and thus being removed from procfs). Try to handle this by formatting the thread name unconditionally with the tid when getting the thread name fails (instead of dereferencing NULL and crashing). Bug: 15406837 Change-Id: Ibf2208b8ce345589e7e9c57e6a307728d1121c5d
Diffstat (limited to 'libutils')
-rw-r--r--libutils/ProcessCallStack.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/libutils/ProcessCallStack.cpp b/libutils/ProcessCallStack.cpp
index f837bcb..db07e56 100644
--- a/libutils/ProcessCallStack.cpp
+++ b/libutils/ProcessCallStack.cpp
@@ -90,6 +90,11 @@ static String8 getThreadName(pid_t tid) {
ALOGE("%s: Failed to open %s", __FUNCTION__, path);
}
+ if (procName == NULL) {
+ // Reading /proc/self/task/%d/comm failed due to a race
+ return String8::format("[err-unknown-tid-%d]", tid);
+ }
+
// Strip ending newline
strtok(procName, "\n");