Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASAN] fix a nullptr dereference error. #116011

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

yingcong-wu
Copy link
Contributor

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.

@llvmbot
Copy link

llvmbot commented Nov 13, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Wu Yingcong (yingcong-wu)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/116011.diff

1 Files Affected:

  • (modified) compiler-rt/lib/asan/asan_descriptions.cpp (+4-6)
diff --git a/compiler-rt/lib/asan/asan_descriptions.cpp b/compiler-rt/lib/asan/asan_descriptions.cpp
index caec79313e22ff..c9f3e4d682d959 100644
--- a/compiler-rt/lib/asan/asan_descriptions.cpp
+++ b/compiler-rt/lib/asan/asan_descriptions.cpp
@@ -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;

Copy link
Collaborator

@vitalybuka vitalybuka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@vitalybuka vitalybuka merged commit 6c9256d into llvm:main Nov 13, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants