[asan] Rewrite Windows/heaprealloc_alloc_zero check to avoid dereference#156211
[asan] Rewrite Windows/heaprealloc_alloc_zero check to avoid dereference#156211
Conversation
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)
|
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Thurston Dang (thurstond) ChangesThe test checks that 1-byte is allocated when malloc(0) is called, by dereferencing 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:
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);
|
mstorsjo
left a comment
There was a problem hiding this comment.
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 |
(Reported to work in llvm#156211 (comment))
Thanks for checking! I've Removed the UNSUPPORTED marking. |
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.