diff options
| author | Mingming Liu <mingmingl@google.com> | 2025-09-10 15:25:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-10 15:25:31 -0700 |
| commit | 1417dafa1db9cb1b2b09438aa9f53ea5ab6e36e2 (patch) | |
| tree | 57f4b1f313c8cf74eed8819870f39c36ea263c68 /compiler-rt/test/asan/TestCases | |
| parent | 898b813bc8a6d0276bf0f4769f5f2f64b34e632d (diff) | |
| parent | b8cefcb601ddaa18482555c4ff363c01a270c2fe (diff) | |
Merge branch 'main' into users/mingmingl-llvm/samplefdo-profile-formatusers/mingmingl-llvm/samplefdo-profile-format
Diffstat (limited to 'compiler-rt/test/asan/TestCases')
7 files changed, 114 insertions, 10 deletions
diff --git a/compiler-rt/test/asan/TestCases/Darwin/duplicate_os_log_reports.cpp b/compiler-rt/test/asan/TestCases/Darwin/duplicate_os_log_reports.cpp index 43ca027c970c..0091ebc09205 100644 --- a/compiler-rt/test/asan/TestCases/Darwin/duplicate_os_log_reports.cpp +++ b/compiler-rt/test/asan/TestCases/Darwin/duplicate_os_log_reports.cpp @@ -1,5 +1,4 @@ // UNSUPPORTED: ios -// REQUIRES: shell // REQUIRES: darwin_log_cmd // RUN: %clangxx_asan -fsanitize-recover=address %s -o %t // RUN: { %env_asan_opts=halt_on_error=0,log_to_syslog=1 %run %t > %t.process_output.txt 2>&1 & } \ diff --git a/compiler-rt/test/asan/TestCases/Linux/read_binary_name_regtest.c b/compiler-rt/test/asan/TestCases/Linux/read_binary_name_regtest.c index 08bf5e125cf4..5d4a812c80d8 100644 --- a/compiler-rt/test/asan/TestCases/Linux/read_binary_name_regtest.c +++ b/compiler-rt/test/asan/TestCases/Linux/read_binary_name_regtest.c @@ -6,8 +6,7 @@ // will be unable to resolve its $ORIGIN due to readlink() restriction and will // thus fail to start, causing the test to die with SIGPIPE when attempting to // talk to it. -// RUN: not ls /usr/include/linux/seccomp.h || ( %clang_asan %s -o %t && ( not env ASAN_OPTIONS=symbolize=0 %run %t 2>&1 ) | FileCheck %s ) -// REQUIRES: shell +// RUN: not ls /usr/include/linux/seccomp.h || %clang_asan %s -o %t || not env ASAN_OPTIONS=symbolize=0 %run %t 2>&1 | FileCheck %s // UNSUPPORTED: android #include <errno.h> 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 8b0bc71b9f5d..6a5f8a1e7ea0 100644 --- a/compiler-rt/test/asan/TestCases/Windows/heaprealloc_alloc_zero.cpp +++ b/compiler-rt/test/asan/TestCases/Windows/heaprealloc_alloc_zero.cpp @@ -1,15 +1,20 @@ // RUN: %clang_cl_asan %Od %MT -o %t %s // RUN: %env_asan_opts=windows_hook_rtl_allocators=true %run %t 2>&1 | FileCheck %s -// 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); diff --git a/compiler-rt/test/asan/TestCases/Windows/rtlallocateheap_realloc_in_place.cpp b/compiler-rt/test/asan/TestCases/Windows/rtlallocateheap_realloc_in_place.cpp new file mode 100644 index 000000000000..35fa9ce57429 --- /dev/null +++ b/compiler-rt/test/asan/TestCases/Windows/rtlallocateheap_realloc_in_place.cpp @@ -0,0 +1,71 @@ +// RUN: %clang_cl_asan %Od %s %Fe%t %MD +// RUN: %env_asan_opts=windows_hook_rtl_allocators=true not %run %t 2>&1 | FileCheck %s + +#include <stdio.h> +#include <windows.h> + +using AllocateFunctionPtr = PVOID(__stdcall *)(PVOID, ULONG, SIZE_T); +using ReAllocateFunctionPtr = PVOID(__stdcall *)(PVOID, ULONG, PVOID, SIZE_T); +using FreeFunctionPtr = PVOID(__stdcall *)(PVOID, ULONG, PVOID); + +int main() { + HMODULE NtDllHandle = GetModuleHandle("ntdll.dll"); + if (!NtDllHandle) { + fputs("Couldn't load ntdll??\n", stderr); + return -1; + } + + auto RtlAllocateHeap_ptr = + (AllocateFunctionPtr)GetProcAddress(NtDllHandle, "RtlAllocateHeap"); + if (RtlAllocateHeap_ptr == 0) { + fputs("Couldn't RtlAllocateHeap\n", stderr); + return -1; + } + + auto RtlReAllocateHeap_ptr = + (ReAllocateFunctionPtr)GetProcAddress(NtDllHandle, "RtlReAllocateHeap"); + if (RtlReAllocateHeap_ptr == 0) { + fputs("Couldn't find RtlReAllocateHeap\n", stderr); + return -1; + } + + auto RtlFreeHeap_ptr = + (FreeFunctionPtr)GetProcAddress(NtDllHandle, "RtlFreeHeap"); + if (RtlFreeHeap_ptr == 0) { + fputs("Couldn't RtlFreeHeap\n", stderr); + return -1; + } + + char *ptr1; + char *ptr2; + ptr2 = ptr1 = (char *)RtlAllocateHeap_ptr(GetProcessHeap(), 0, 15); + if (ptr1) + fputs("Okay alloc\n", stderr); + // CHECK: Okay alloc + + // TODO: Growing is currently not supported + ptr2 = (char *)RtlReAllocateHeap_ptr(GetProcessHeap(), + HEAP_REALLOC_IN_PLACE_ONLY, ptr1, 23); + if (ptr2 == NULL) + fputs("Okay grow failed\n", stderr); + // CHECK: Okay grow failed + + // TODO: Shrinking is currently not supported + ptr2 = (char *)RtlReAllocateHeap_ptr(GetProcessHeap(), + HEAP_REALLOC_IN_PLACE_ONLY, ptr1, 7); + if (ptr2 == ptr1) + fputs("Okay shrinking return the original pointer\n", stderr); + // CHECK: Okay shrinking return the original pointer + + ptr1[7] = 'a'; + fputs("Okay 7\n", stderr); + // CHECK: Okay 7 + + // TODO: Writing behind the shrinked part is currently not detected. + // Therefore test writing behind the original allocation for now. + ptr1[16] = 'a'; + // CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] + // CHECK: WRITE of size 1 at [[ADDR]] thread T0 + + RtlFreeHeap_ptr(GetProcessHeap(), 0, ptr1); +} diff --git a/compiler-rt/test/asan/TestCases/suppressions-library.cpp b/compiler-rt/test/asan/TestCases/suppressions-library.cpp index 5427122eaa92..9d1f5d4888e3 100644 --- a/compiler-rt/test/asan/TestCases/suppressions-library.cpp +++ b/compiler-rt/test/asan/TestCases/suppressions-library.cpp @@ -4,8 +4,6 @@ // Check that without suppressions, we catch the issue. // RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s -// REQUIRES: shell - // RUN: echo "interceptor_via_lib:"%xdynamiclib_filename > %t.supp // RUN: %env_asan_opts=suppressions='"%t.supp"' %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s diff --git a/compiler-rt/test/asan/TestCases/verbose-log-path_test.cpp b/compiler-rt/test/asan/TestCases/verbose-log-path_test.cpp index 37c1dab6db8e..2c094c484371 100644 --- a/compiler-rt/test/asan/TestCases/verbose-log-path_test.cpp +++ b/compiler-rt/test/asan/TestCases/verbose-log-path_test.cpp @@ -1,9 +1,6 @@ // RUN: rm -rf %t-dir && mkdir -p %t-dir // RUN: %clangxx_asan %s -o %t-dir/verbose-log-path_test-binary -// The glob below requires bash. -// REQUIRES: shell - // Good log_path. // RUN: rm -f %t-dir/asan.log.* // RUN: %env_asan_opts=log_path=%t-dir/asan.log:log_exe_name=1 not %run %t-dir/verbose-log-path_test-binary 2> %t.out diff --git a/compiler-rt/test/asan/TestCases/zero_alloc.cpp b/compiler-rt/test/asan/TestCases/zero_alloc.cpp new file mode 100644 index 000000000000..aa807f44ed3b --- /dev/null +++ b/compiler-rt/test/asan/TestCases/zero_alloc.cpp @@ -0,0 +1,35 @@ +// RUN: %clang_asan -Wno-alloc-size -fsanitize-recover=address %s -o %t && %env_asan_opts=halt_on_error=0 %run %t 2>&1 | FileCheck %s + +#include <stdio.h> +#include <stdlib.h> + +int main(int argc, char **argv) { + { + char *p1 = (char *)calloc(1, 0); + printf("p1 is %p\n", p1); + printf("Content of p1 is: %d\n", *p1); + // CHECK: ERROR: AddressSanitizer: heap-buffer-overflow + // CHECK: {{#0 0x.* in main .*zero_alloc.cpp:}}[[@LINE-2]] + free(p1); + } + + { + char *p2 = (char *)calloc(0, 1); + printf("p2 is %p\n", p2); + printf("Content of p2 is: %d\n", *p2); + // CHECK: ERROR: AddressSanitizer: heap-buffer-overflow + // CHECK: {{#0 0x.* in main .*zero_alloc.cpp:}}[[@LINE-2]] + free(p2); + } + + { + char *p3 = (char *)malloc(0); + printf("p3 is %p\n", p3); + printf("Content of p2 is: %d\n", *p3); + // CHECK: ERROR: AddressSanitizer: heap-buffer-overflow + // CHECK: {{#0 0x.* in main .*zero_alloc.cpp:}}[[@LINE-2]] + free(p3); + } + + return 0; +} |
