[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.
This commit is contained in:
Wu Yingcong 2024-11-14 07:46:57 +08:00 committed by GitHub
parent adfa6b762d
commit 6c9256dc5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -45,6 +45,9 @@ 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
@ -52,12 +55,7 @@ void DescribeThread(AsanThreadContext *context) {
// `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;