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

[hwasan] Fix a possible null dereference problem #77737

Merged
merged 1 commit into from
Jan 22, 2024

Conversation

yingcong-wu
Copy link
Contributor

@yingcong-wu yingcong-wu commented Jan 11, 2024

This is clearly a copy-paste mistake, fix it with this patch.
After checking the local.function_name is not null, it should check the len for local.function_name, not local.name. And this could lead to possible null dereference since the second internal_strlen(local.name) does not guarantee local.name is not null.

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 11, 2024

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

Author: Wu Yingcong (yingcong-wu)

Changes

This is clearly a copy-paste mistake, fix it with this patch.


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

1 Files Affected:

  • (modified) compiler-rt/lib/hwasan/hwasan_report.cpp (+1-1)
diff --git a/compiler-rt/lib/hwasan/hwasan_report.cpp b/compiler-rt/lib/hwasan/hwasan_report.cpp
index 784cfb904aa275..12a4fa47f21519 100644
--- a/compiler-rt/lib/hwasan/hwasan_report.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_report.cpp
@@ -222,7 +222,7 @@ static void PrintStackAllocations(const StackAllocationsRingBuffer *sa,
         if (!local.has_frame_offset || !local.has_size || !local.has_tag_offset)
           continue;
         if (!(local.name && internal_strlen(local.name)) &&
-            !(local.function_name && internal_strlen(local.name)) &&
+            !(local.function_name && internal_strlen(local.function_name)) &&
             !(local.decl_file && internal_strlen(local.decl_file)))
           continue;
         tag_t obj_tag = base_tag ^ local.tag_offset;

@yingcong-wu yingcong-wu changed the title [hwasan] Fix a copy-paste mistake. [hwasan] Fix a possible null dereference problem Jan 11, 2024
@MaskRay
Copy link
Member

MaskRay commented Jan 12, 2024

Is a test case possible?

@yingcong-wu
Copy link
Contributor Author

Let me see what I can do to add a test case.

@yingcong-wu
Copy link
Contributor Author

Sorry, I cannot think of a way to add test for this. Do you have any suggestions?

@yingcong-wu
Copy link
Contributor Author

Hi, I don't have any ideas on how to build a test case for this, could you please give some direction?
Or can we land this patch without a test?

@yingcong-wu
Copy link
Contributor Author

Hi @fmayer , could we land this patch without a test?

@vitalybuka
Copy link
Collaborator

I don't know if easy, or even possible, to trigger this case in test.

@vitalybuka vitalybuka merged commit 8bef13e into llvm:main Jan 22, 2024
8 checks passed
@vitalybuka
Copy link
Collaborator

Thanks for the fix!

@yingcong-wu
Copy link
Contributor Author

No problems.

@yingcong-wu yingcong-wu deleted the patch-1 branch January 22, 2024 06:11
harbandana pushed a commit to harbandana/LLVM-REPO that referenced this pull request Jan 22, 2024
Kaur-sukhmani pushed a commit to Kaur-sukhmani/LLVM_project that referenced this pull request Jan 22, 2024
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.

None yet

5 participants