Skip to content

Commit

Permalink
[asan] Prevent printing invalid parent thread (#111916)
Browse files Browse the repository at this point in the history
By default reuse can happend only after
`UINT32_MAX` threads, so it's almost NFC.
  • Loading branch information
vitalybuka authored Oct 11, 2024
1 parent 774c953 commit 9c81a24
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions compiler-rt/lib/asan/asan_descriptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,20 @@ void DescribeThread(AsanThreadContext *context) {
return;
}
context->announced = true;

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 (context->parent_tid == kInvalidTid) {
if (!parent_context) {
str.Append(" created by unknown thread\n");
Printf("%s", str.data());
return;
Expand All @@ -60,11 +71,8 @@ void DescribeThread(AsanThreadContext *context) {
Printf("%s", str.data());
StackDepotGet(context->stack_id).Print();
// Recursively described parent thread if needed.
if (flags()->print_full_thread_history) {
AsanThreadContext *parent_context =
GetThreadContextByTidLocked(context->parent_tid);
if (flags()->print_full_thread_history)
DescribeThread(parent_context);
}
}

// Shadow descriptions
Expand Down

0 comments on commit 9c81a24

Please sign in to comment.