Skip to content

Conversation

@Camsyn
Copy link
Contributor

@Camsyn Camsyn commented Jun 13, 2025

Previously,

  1. ifaddrs.cpp : mistake size_t (xxx) as sizeof (xxx), resulting in
    inadequate checks.
  2. qsort.cpp : mistake kSize2 as kSize1, resulting in an unexpected
    buffer overlow issue.

@llvmbot
Copy link
Member

llvmbot commented Jun 13, 2025

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

Author: Kunqiu Chen (Camsyn)

Changes

Previously,

  1. ifaddrs.cpp : mistake size_t (xxx) as sizeof (xxx), resulting in
    inadequate checks.
  2. qsort.cpp : mistake kSize2 as kSize1, resulting in an unexpected
    buffer overlow issue.

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

2 Files Affected:

  • (modified) compiler-rt/test/msan/ifaddrs.cpp (+1-1)
  • (modified) compiler-rt/test/msan/qsort.cpp (+1-1)
diff --git a/compiler-rt/test/msan/ifaddrs.cpp b/compiler-rt/test/msan/ifaddrs.cpp
index 91730a01f2d8a..2379e8ebb6477 100644
--- a/compiler-rt/test/msan/ifaddrs.cpp
+++ b/compiler-rt/test/msan/ifaddrs.cpp
@@ -18,7 +18,7 @@
 
 #define CHECK_AND_PUSH(addr, size)                                \
   if (addr) {                                                     \
-    assert(-1 == __msan_test_shadow(addr, sizeof(size)));         \
+    assert(-1 == __msan_test_shadow(addr, (size_t)(size)));       \
     ranges.push_back(std::make_pair((void *)addr, (size_t)size)); \
   }
 
diff --git a/compiler-rt/test/msan/qsort.cpp b/compiler-rt/test/msan/qsort.cpp
index af287ed64357e..93e6845e1ea7a 100644
--- a/compiler-rt/test/msan/qsort.cpp
+++ b/compiler-rt/test/msan/qsort.cpp
@@ -52,7 +52,7 @@ int compar1(const void *a, const void *b) {
   // kind of random
   for (int i = 0; i < kSize2; ++i)
     p[i] = i * 2 + (i % 3 - 1) * 3;
-  qsort(p, kSize1, sizeof(long), compar2);
+  qsort(p, kSize2, sizeof(long), compar2);
   __msan_check_mem_is_initialized(p, sizeof(long) * kSize2);
   delete[] p;
 

@github-actions
Copy link

github-actions bot commented Jun 13, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Previously,
1. ifaddrs.cpp : mistake `size_t (xxx)` as `sizeof (xxx)`, resulting in
inadequate checks.
2. qsort.cpp : mistake `kSize2` as `kSize1`, resulting in an unexpected
buffer overlow issue.
Copy link
Contributor

@fmayer fmayer left a comment

Choose a reason for hiding this comment

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

lgtm

@Camsyn Camsyn merged commit 2796c41 into llvm:main Jun 14, 2025
7 checks passed
@Camsyn Camsyn deleted the msan-test branch June 14, 2025 10:04
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
Previously,
1. ifaddrs.cpp : mistake `size_t (xxx)` as `sizeof (xxx)`, resulting in 
inadequate checks.
2. qsort.cpp : mistake `kSize2` as `kSize1`, resulting in an unexpected
buffer overlow issue.
akuhlens pushed a commit to akuhlens/llvm-project that referenced this pull request Jun 24, 2025
Previously,
1. ifaddrs.cpp : mistake `size_t (xxx)` as `sizeof (xxx)`, resulting in 
inadequate checks.
2. qsort.cpp : mistake `kSize2` as `kSize1`, resulting in an unexpected
buffer overlow issue.
Camsyn added a commit that referenced this pull request Jul 25, 2025
Supplement to PR #144073

Previously, _msan_check_mem_is_initialized.cpp_ initialized a 32-byte
stack array, but checked the shadow for the offset range [12, 42),
exceeding the stack array size.

MSan does not guarantee that the shadow corresponding to the overflow
part is 0, so it is undefined to require the overflow part to be
unpoisoned.
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Jul 28, 2025
Supplement to PR llvm#144073

Previously, _msan_check_mem_is_initialized.cpp_ initialized a 32-byte
stack array, but checked the shadow for the offset range [12, 42),
exceeding the stack array size.

MSan does not guarantee that the shadow corresponding to the overflow
part is 0, so it is undefined to require the overflow part to be
unpoisoned.
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