Skip to content

Commit cb5e1f2

Browse files
committed
[asan] Rewrite Windows/heaprealloc_alloc_zero check to avoid dereference
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)
1 parent 2824b3c commit cb5e1f2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

compiler-rt/test/asan/TestCases/Windows/heaprealloc_alloc_zero.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33
// UNSUPPORTED: asan-64-bits
44
#include <cassert>
55
#include <iostream>
6+
#include <sanitizer/allocator_interface.h>
67
#include <windows.h>
78

89
int main() {
910
void *ptr = malloc(0);
1011
if (ptr)
1112
std::cerr << "allocated!\n";
12-
((char *)ptr)[0] = '\xff'; //check this 'allocate 1 instead of 0' hack hasn't changed
13+
14+
// Check the 'allocate 1 instead of 0' hack hasn't changed
15+
// Note that as of b3452d90b043a398639e62b0ab01aa339cc649de, dereferencing
16+
// the pointer will be detected as a heap-buffer-overflow.
17+
if (__sanitizer_get_allocated_size(ptr) != 1)
18+
return 1;
1319

1420
free(ptr);
1521

0 commit comments

Comments
 (0)