Skip to content

Commit 6c9256d

Browse files
authored
[ASAN] fix a nullptr dereference error. (#116011)
`parent_context` is used without checking for nullptr and we can see in LINE 50 that it could totally be nullptr. This patch addresses this issue.
1 parent adfa6b7 commit 6c9256d

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

compiler-rt/lib/asan/asan_descriptions.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,17 @@ void DescribeThread(AsanThreadContext *context) {
4545
}
4646
context->announced = true;
4747

48+
InternalScopedString str;
49+
str.AppendF("Thread %s", AsanThreadIdAndName(context).c_str());
50+
4851
AsanThreadContext *parent_context =
4952
context->parent_tid == kInvalidTid
5053
? nullptr
5154
: GetThreadContextByTidLocked(context->parent_tid);
5255

5356
// `context->parent_tid` may point to reused slot. Check `unique_id` which
5457
// is always smaller for the parent, always greater for a new user.
55-
if (context->unique_id <= parent_context->unique_id)
56-
parent_context = nullptr;
57-
58-
InternalScopedString str;
59-
str.AppendF("Thread %s", AsanThreadIdAndName(context).c_str());
60-
if (!parent_context) {
58+
if (!parent_context || context->unique_id <= parent_context->unique_id) {
6159
str.Append(" created by unknown thread\n");
6260
Printf("%s", str.data());
6361
return;

0 commit comments

Comments
 (0)