diff options
Diffstat (limited to 'test/asan/TestCases/Posix')
-rw-r--r-- | test/asan/TestCases/Posix/asan-sigbus.cpp | 40 | ||||
-rw-r--r-- | test/asan/TestCases/Posix/closed-fds.cc | 3 | ||||
-rw-r--r-- | test/asan/TestCases/Posix/coverage-maybe-open-file.cc | 3 | ||||
-rw-r--r-- | test/asan/TestCases/Posix/coverage-sandboxing.cc | 6 | ||||
-rw-r--r-- | test/asan/TestCases/Posix/coverage.cc | 12 | ||||
-rw-r--r-- | test/asan/TestCases/Posix/deep_call_stack.cc | 5 | ||||
-rw-r--r-- | test/asan/TestCases/Posix/fread_fwrite.cc | 34 | ||||
-rw-r--r-- | test/asan/TestCases/Posix/halt_on_error-torture.cc | 2 | ||||
-rw-r--r-- | test/asan/TestCases/Posix/halt_on_error_suppress_equal_pcs.cc | 4 | ||||
-rw-r--r-- | test/asan/TestCases/Posix/stack-use-after-return.cc | 40 | ||||
-rw-r--r-- | test/asan/TestCases/Posix/start-deactivated.cc | 2 |
11 files changed, 129 insertions, 22 deletions
diff --git a/test/asan/TestCases/Posix/asan-sigbus.cpp b/test/asan/TestCases/Posix/asan-sigbus.cpp new file mode 100644 index 0000000000000..e07392b4cd4b0 --- /dev/null +++ b/test/asan/TestCases/Posix/asan-sigbus.cpp @@ -0,0 +1,40 @@ +// Check handle_bus flag +// Defaults to true +// RUN: %clangxx_asan -std=c++11 %s -o %t +// RUN: not %run %t %T/file 2>&1 | FileCheck %s -check-prefix=CHECK-BUS +// RUN: %env_asan_opts=handle_sigbus=false not --crash %run %t %T/file 2>&1 | FileCheck %s + +#include <assert.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/mman.h> +#include <unistd.h> + +char array[4096]; +int main(int argc, char **argv) { + assert(argc > 1); + int fd = open(argv[1], O_RDWR | O_CREAT, 0700); + if (fd < 0) { + perror("open"); + exit(1); + } + assert(write(fd, array, sizeof(array)) == sizeof(array)); + + // Write some zeroes to the file, then mmap it while it has a 4KiB size + char *addr = (char *)mmap(nullptr, sizeof(array), PROT_READ, + MAP_FILE | MAP_SHARED, fd, 0); + if (addr == MAP_FAILED) { + perror("mmap"); + exit(1); + } + + // Truncate the file so our memory isn't valid any more + assert(ftruncate(fd, 0) == 0); + + // Try to access the memory + return addr[42]; + // CHECK-NOT: DEADLYSIGNAL + // CHECK-BUS: DEADLYSIGNAL + // CHECK-BUS: ERROR: AddressSanitizer: BUS +} diff --git a/test/asan/TestCases/Posix/closed-fds.cc b/test/asan/TestCases/Posix/closed-fds.cc index b7bca26c305d5..75e3216aab5ad 100644 --- a/test/asan/TestCases/Posix/closed-fds.cc +++ b/test/asan/TestCases/Posix/closed-fds.cc @@ -2,7 +2,8 @@ // symbolizer still works. // RUN: rm -f %t.log.* -// RUN: %clangxx_asan -O0 %s -o %t 2>&1 && %env_asan_opts=log_path='"%t.log"':verbosity=2 not %run %t 2>&1 +// RUN: %clangxx_asan -O0 %s -o %t +// RUN: %env_asan_opts=log_path='"%t.log"':verbosity=2 not %run %t // RUN: FileCheck %s --check-prefix=CHECK-FILE < %t.log.* // FIXME: copy %t.log back from the device and re-enable on Android. diff --git a/test/asan/TestCases/Posix/coverage-maybe-open-file.cc b/test/asan/TestCases/Posix/coverage-maybe-open-file.cc index cab3d5770aa5a..95f2b5449e838 100644 --- a/test/asan/TestCases/Posix/coverage-maybe-open-file.cc +++ b/test/asan/TestCases/Posix/coverage-maybe-open-file.cc @@ -6,7 +6,7 @@ // RUN: mkdir -p %T/coverage-maybe-open-file && cd %T/coverage-maybe-open-file // RUN: %env_asan_opts=coverage=1 %run %t | FileCheck %s --check-prefix=CHECK-success // RUN: %env_asan_opts=coverage=0 %run %t | FileCheck %s --check-prefix=CHECK-fail -// RUN: [ "$(cat test.sancov.packed)" == "test" ] +// RUN: FileCheck %s < test.sancov.packed -implicit-check-not={{.}} --check-prefix=CHECK-test // RUN: cd .. && rm -rf %T/coverage-maybe-open-file #include <stdio.h> @@ -30,3 +30,4 @@ int main(int argc, char **argv) { // CHECK-success: SUCCESS // CHECK-fail: FAIL +// CHECK-test: {{^}}test{{$}} diff --git a/test/asan/TestCases/Posix/coverage-sandboxing.cc b/test/asan/TestCases/Posix/coverage-sandboxing.cc index c4e6bc7eef8ac..431dce149525e 100644 --- a/test/asan/TestCases/Posix/coverage-sandboxing.cc +++ b/test/asan/TestCases/Posix/coverage-sandboxing.cc @@ -12,9 +12,9 @@ // RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t a b 2>&1 | FileCheck %s --check-prefix=CHECK-sandbox // RUN: %sancov unpack coverage_sandboxing_test.sancov.packed // RUN: cd .. -// RUN: %sancov print vanilla/`basename %dynamiclib`*.sancov > vanilla.txt -// RUN: %sancov print sandbox1/`basename %dynamiclib`*.sancov > sandbox1.txt -// RUN: %sancov print sandbox2/`basename %dynamiclib`*.sancov > sandbox2.txt +// RUN: %sancov print vanilla/%xdynamiclib_filename*.sancov > vanilla.txt +// RUN: %sancov print sandbox1/%xdynamiclib_filename*.sancov > sandbox1.txt +// RUN: %sancov print sandbox2/%xdynamiclib_filename*.sancov > sandbox2.txt // RUN: diff vanilla.txt sandbox1.txt // RUN: diff vanilla.txt sandbox2.txt // RUN: rm -r %T/coverage_sandboxing_test diff --git a/test/asan/TestCases/Posix/coverage.cc b/test/asan/TestCases/Posix/coverage.cc index 7c1c4949f60c5..3d1dccfbd549f 100644 --- a/test/asan/TestCases/Posix/coverage.cc +++ b/test/asan/TestCases/Posix/coverage.cc @@ -2,15 +2,15 @@ // RUN: %clangxx_asan -fsanitize-coverage=func %s %ld_flags_rpath_exe -o %t // RUN: rm -rf %T/coverage && mkdir -p %T/coverage && cd %T/coverage // RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-main -// RUN: %sancov print `ls coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1 +// RUN: %sancov print coverage.*sancov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1 // RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t foo 2>&1 | FileCheck %s --check-prefix=CHECK-foo -// RUN: %sancov print `ls coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2 +// RUN: %sancov print coverage.*sancov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2 // RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t bar 2>&1 | FileCheck %s --check-prefix=CHECK-bar -// RUN: %sancov print `ls *coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2 +// RUN: %sancov print coverage.*sancov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2 // RUN: %env_asan_opts=coverage=1:verbosity=1 %run %t foo bar 2>&1 | FileCheck %s --check-prefix=CHECK-foo-bar -// RUN: %sancov print `ls *coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2 -// RUN: %sancov print `ls *coverage.*sancov | grep '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1 -// RUN: %sancov merge `ls *coverage.*sancov | grep -v '.so'` > merged-cov +// RUN: %sancov print coverage.*sancov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2 +// RUN: %sancov print libcoverage.*sancov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1 +// RUN: %sancov merge coverage.*sancov > merged-cov // RUN: %sancov print merged-cov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2 // RUN: %env_asan_opts=coverage=1:verbosity=1 not %run %t foo bar 4 2>&1 | FileCheck %s --check-prefix=CHECK-report // RUN: %env_asan_opts=coverage=1:verbosity=1 not %run %t foo bar 4 5 2>&1 | FileCheck %s --check-prefix=CHECK-segv diff --git a/test/asan/TestCases/Posix/deep_call_stack.cc b/test/asan/TestCases/Posix/deep_call_stack.cc index 18ba563dbd21f..2d2b056d638d0 100644 --- a/test/asan/TestCases/Posix/deep_call_stack.cc +++ b/test/asan/TestCases/Posix/deep_call_stack.cc @@ -1,6 +1,7 @@ // Check that UAR mode can handle very deep recusrion. -// RUN: %clangxx_asan -O2 %s -o %t && \ -// RUN: (ulimit -s 4096; %env_asan_opts=detect_stack_use_after_return=1 %run %t) 2>&1 | FileCheck %s +// RUN: %clangxx_asan -O2 %s -o %t +// RUN: ulimit -s 4096 +// RUN: %env_asan_opts=detect_stack_use_after_return=1 %run %t 2>&1 | FileCheck %s // Also check that use_sigaltstack+verbosity doesn't crash. // RUN: %env_asan_opts=verbosity=1:use_sigaltstack=1:detect_stack_use_after_return=1 %run %t | FileCheck %s diff --git a/test/asan/TestCases/Posix/fread_fwrite.cc b/test/asan/TestCases/Posix/fread_fwrite.cc new file mode 100644 index 0000000000000..97d44b7528ba9 --- /dev/null +++ b/test/asan/TestCases/Posix/fread_fwrite.cc @@ -0,0 +1,34 @@ +// RUN: %clangxx_asan -g %s -o %t +// RUN: not %t 2>&1 | FileCheck %s --check-prefix=CHECK-FWRITE +// RUN: not %t 1 2>&1 | FileCheck %s --check-prefix=CHECK-FREAD + +#include <stdio.h> +#include <stdlib.h> + +int test_fread() { + FILE *f = fopen("/dev/zero", "r"); + char buf[2]; + fread(buf, sizeof(buf), 2, f); // BOOM + fclose(f); + return 0; +} + +int test_fwrite() { + FILE *f = fopen("/dev/null", "w"); + char buf[2]; + fwrite(buf, sizeof(buf), 2, f); // BOOM + return fclose(f); +} + +int main(int argc, char *argv[]) { + if (argc > 1) + test_fread(); + else + test_fwrite(); + return 0; +} + +// CHECK-FREAD: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}} +// CHECK-FREAD: #{{.*}} in {{(wrap_|__interceptor_)?}}fread +// CHECK-FWRITE: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}} +// CHECK-FWRITE: #{{.*}} in {{(wrap_|__interceptor_)?}}fwrite diff --git a/test/asan/TestCases/Posix/halt_on_error-torture.cc b/test/asan/TestCases/Posix/halt_on_error-torture.cc index 5d7eff06e34e6..1b26173d713fd 100644 --- a/test/asan/TestCases/Posix/halt_on_error-torture.cc +++ b/test/asan/TestCases/Posix/halt_on_error-torture.cc @@ -5,7 +5,7 @@ // RUN: rm -f 1.txt // RUN: %env_asan_opts=halt_on_error=false:suppress_equal_pcs=false %run %t 1 10 >>1.txt 2>&1 // RUN: FileCheck %s < 1.txt -// RUN: [ $(grep -c 'ERROR: AddressSanitizer: use-after-poison' 1.txt) -eq 10 ] +// RUN: grep 'ERROR: AddressSanitizer: use-after-poison' 1.txt | count 10 // RUN: FileCheck --check-prefix=CHECK-NO-COLLISION %s < 1.txt // // Collisions are unlikely but still possible so we need the ||. diff --git a/test/asan/TestCases/Posix/halt_on_error_suppress_equal_pcs.cc b/test/asan/TestCases/Posix/halt_on_error_suppress_equal_pcs.cc index 98ef851657b7d..b9d85ef94b230 100644 --- a/test/asan/TestCases/Posix/halt_on_error_suppress_equal_pcs.cc +++ b/test/asan/TestCases/Posix/halt_on_error_suppress_equal_pcs.cc @@ -8,7 +8,7 @@ // Check that we die after reaching different reports number threshold. // RUN: rm -f %t1.log // RUN: %env_asan_opts=halt_on_error=false not %run %t 1 >> %t1.log 2>&1 -// RUN: [ $(grep -c 'ERROR: AddressSanitizer: stack-buffer-overflow' %t1.log) -eq 25 ] +// RUN: grep 'ERROR: AddressSanitizer: stack-buffer-overflow' %t1.log | count 25 // // Check suppress_equal_pcs=true behavior is equal to default one. // RUN: %env_asan_opts=halt_on_error=false:suppress_equal_pcs=true %run %t 2>&1 | FileCheck %s @@ -16,7 +16,7 @@ // Check suppress_equal_pcs=false behavior isn't equal to default one. // RUN: rm -f %t2.log // RUN: %env_asan_opts=halt_on_error=false:suppress_equal_pcs=false %run %t >> %t2.log 2>&1 -// RUN: [ $(grep -c 'ERROR: AddressSanitizer: stack-buffer-overflow' %t2.log) -eq 30 ] +// RUN: grep 'ERROR: AddressSanitizer: stack-buffer-overflow' %t2.log | count 30 #define ACCESS_ARRAY_FIVE_ELEMENTS(array, i) \ array[i] = i; \ diff --git a/test/asan/TestCases/Posix/stack-use-after-return.cc b/test/asan/TestCases/Posix/stack-use-after-return.cc index cf114be97d514..822d5be9491e7 100644 --- a/test/asan/TestCases/Posix/stack-use-after-return.cc +++ b/test/asan/TestCases/Posix/stack-use-after-return.cc @@ -4,7 +4,7 @@ // RUN: %clangxx_asan -O3 %s -pthread -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s // RUN: %env_asan_opts=detect_stack_use_after_return=0 %run %t // Regression test for a CHECK failure with small stack size and large frame. -// RUN: %clangxx_asan -O3 %s -pthread -o %t -DkSize=10000 -DUseThread -DkStackSize=65536 && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck --check-prefix=THREAD %s +// RUN: %clangxx_asan -O3 %s -pthread -o %t -DkSize=10000 -DUseThread -DkStackSize=131072 && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck --check-prefix=THREAD %s // // Test that we can find UAR in a thread other than main: // RUN: %clangxx_asan -DUseThread -O2 %s -pthread -o %t && %env_asan_opts=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck --check-prefix=THREAD %s @@ -14,8 +14,13 @@ // RUN: %env_asan_opts=detect_stack_use_after_return=1:max_uar_stack_size_log=20:verbosity=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-20 %s // RUN: %env_asan_opts=detect_stack_use_after_return=1:min_uar_stack_size_log=24:max_uar_stack_size_log=24:verbosity=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-24 %s -#include <stdio.h> +// This test runs out of stack on AArch64. +// UNSUPPORTED: aarch64 + +#include <limits.h> #include <pthread.h> +#include <stdio.h> +#include <stdlib.h> #ifndef kSize # define kSize 1 @@ -48,11 +53,11 @@ void Func2(char *x) { // CHECK: WRITE of size 1 {{.*}} thread T0 // CHECK: #0{{.*}}Func2{{.*}}stack-use-after-return.cc:[[@LINE-2]] // CHECK: is located in stack of thread T0 at offset - // CHECK: 'local' <== Memory access at offset {{16|32}} is inside this variable + // CHECK: 'local'{{.*}} <== Memory access at offset {{16|32}} is inside this variable // THREAD: WRITE of size 1 {{.*}} thread T{{[1-9]}} // THREAD: #0{{.*}}Func2{{.*}}stack-use-after-return.cc:[[@LINE-6]] // THREAD: is located in stack of thread T{{[1-9]}} at offset - // THREAD: 'local' <== Memory access at offset {{16|32}} is inside this variable + // THREAD: 'local'{{.*}} <== Memory access at offset {{16|32}} is inside this variable // CHECK-20: T0: FakeStack created:{{.*}} stack_size_log: 20 // CHECK-24: T0: FakeStack created:{{.*}} stack_size_log: 24 } @@ -66,8 +71,31 @@ int main(int argc, char **argv) { #if UseThread pthread_attr_t attr; pthread_attr_init(&attr); - if (kStackSize > 0) - pthread_attr_setstacksize(&attr, kStackSize); + if (kStackSize > 0) { + size_t desired_stack_size = kStackSize; + if (desired_stack_size < PTHREAD_STACK_MIN) { + desired_stack_size = PTHREAD_STACK_MIN; + } + + int ret = pthread_attr_setstacksize(&attr, desired_stack_size); + if (ret != 0) { + fprintf(stderr, "pthread_attr_setstacksize returned %d\n", ret); + abort(); + } + + size_t stacksize_check; + ret = pthread_attr_getstacksize(&attr, &stacksize_check); + if (ret != 0) { + fprintf(stderr, "pthread_attr_getstacksize returned %d\n", ret); + abort(); + } + + if (stacksize_check != desired_stack_size) { + fprintf(stderr, "Unable to set stack size to %d, the stack size is %d.\n", + desired_stack_size, stacksize_check); + abort(); + } + } pthread_t t; pthread_create(&t, &attr, Thread, 0); pthread_attr_destroy(&attr); diff --git a/test/asan/TestCases/Posix/start-deactivated.cc b/test/asan/TestCases/Posix/start-deactivated.cc index b223f04e46a9c..2a2aa674c04c5 100644 --- a/test/asan/TestCases/Posix/start-deactivated.cc +++ b/test/asan/TestCases/Posix/start-deactivated.cc @@ -20,6 +20,8 @@ // XFAIL: arm-linux-gnueabi +// END. + #if !defined(SHARED_LIB) #include <assert.h> |