Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 63fbdb64 authored by Igor Murashkin's avatar Igor Murashkin
Browse files

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
parent 342a2264
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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");