Skip to content

Commit

Permalink
[ASAN] fix a nullptr dereference error. (llvm#116011)
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
yingcong-wu authored Nov 13, 2024
1 parent adfa6b7 commit 6c9256d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions compiler-rt/lib/asan/asan_descriptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,17 @@ void DescribeThread(AsanThreadContext *context) {
}
context->announced = true;

InternalScopedString str;
str.AppendF("Thread %s", AsanThreadIdAndName(context).c_str());

AsanThreadContext *parent_context =
context->parent_tid == kInvalidTid
? nullptr
: GetThreadContextByTidLocked(context->parent_tid);

// `context->parent_tid` may point to reused slot. Check `unique_id` which
// is always smaller for the parent, always greater for a new user.
if (context->unique_id <= parent_context->unique_id)
parent_context = nullptr;

InternalScopedString str;
str.AppendF("Thread %s", AsanThreadIdAndName(context).c_str());
if (!parent_context) {
if (!parent_context || context->unique_id <= parent_context->unique_id) {
str.Append(" created by unknown thread\n");
Printf("%s", str.data());
return;
Expand Down

0 comments on commit 6c9256d

Please sign in to comment.