Skip to content

Conversation

thurstond
Copy link
Contributor

@thurstond thurstond commented Aug 30, 2025

The test currently checks that 1-byte is allocated when malloc(0) is called, by dereferencing the pointer.
#155943 changed ASan to consider the dereference to be a heap buffer overflow. This patch changes the test to check the allocated size is still 1-byte, but not dereference the pointer.

This aims to fix the breakage reported in #155943 (comment)

It also enables the test for 64-bit Windows.

The test checks that 1-byte is allocated when malloc(0) is called, by
dereferencing the pointer.
llvm#155943 changed ASan to
consider the dereference to be a heap buffer overflow. This patch
changes the test to check the allocated size is still 1-byte, but not dereference the
pointer.

This aims to fix the breakage reported in llvm#155943 (comment)
@llvmbot
Copy link
Member

llvmbot commented Aug 30, 2025

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

Author: Thurston Dang (thurstond)

Changes

The test checks that 1-byte is allocated when malloc(0) is called, by dereferencing the pointer.
#155943 changed ASan to consider the dereference to be a heap buffer overflow. This patch changes the test to check the allocated size is still 1-byte, but not dereference the pointer.

This aims to fix the breakage reported in #155943 (comment)


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

1 Files Affected:

  • (modified) compiler-rt/test/asan/TestCases/Windows/heaprealloc_alloc_zero.cpp (+7-1)
diff --git a/compiler-rt/test/asan/TestCases/Windows/heaprealloc_alloc_zero.cpp b/compiler-rt/test/asan/TestCases/Windows/heaprealloc_alloc_zero.cpp
index 8b0bc71b9f5db..e9be0d5b4c7df 100644
--- a/compiler-rt/test/asan/TestCases/Windows/heaprealloc_alloc_zero.cpp
+++ b/compiler-rt/test/asan/TestCases/Windows/heaprealloc_alloc_zero.cpp
@@ -3,13 +3,19 @@
 // UNSUPPORTED: asan-64-bits
 #include <cassert>
 #include <iostream>
+#include <sanitizer/allocator_interface.h>
 #include <windows.h>
 
 int main() {
   void *ptr = malloc(0);
   if (ptr)
     std::cerr << "allocated!\n";
-  ((char *)ptr)[0] = '\xff'; //check this 'allocate 1 instead of 0' hack hasn't changed
+
+  // Check the 'allocate 1 instead of 0' hack hasn't changed
+  // Note that as of b3452d90b043a398639e62b0ab01aa339cc649de, dereferencing
+  // the pointer will be detected as a heap-buffer-overflow.
+  if (__sanitizer_get_allocated_size(ptr) != 1)
+    return 1;
 
   free(ptr);
 

Copy link
Member

@mstorsjo mstorsjo left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! This does seem to fix the test for me.

(Side note - is the UNSUPPORTED: asan-64-bits still relevant here you think?)

@mstorsjo
Copy link
Member

LGTM, thanks! This does seem to fix the test for me.

(Side note - is the UNSUPPORTED: asan-64-bits still relevant here you think?)

I checked; before b3452d9, this test did indeed fail on 64 bit. With the recent changes and this fix, this test does pass on 64 bit as well, so the UNSUPPORTED marking can be removed at the same time.

@thurstond
Copy link
Contributor Author

LGTM, thanks! This does seem to fix the test for me.
(Side note - is the UNSUPPORTED: asan-64-bits still relevant here you think?)

I checked; before b3452d9, this test did indeed fail on 64 bit. With the recent changes and this fix, this test does pass on 64 bit as well, so the UNSUPPORTED marking can be removed at the same time.

Thanks for checking! I've Removed the UNSUPPORTED marking.

@thurstond thurstond merged commit 6dfd8d0 into llvm:main Aug 30, 2025
9 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