summaryrefslogtreecommitdiff
path: root/test/asan
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-06-26 20:33:22 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-06-26 20:33:22 +0000
commit10fcf738d732204a1f1e28878d68a27c5f12cf3b (patch)
tree7c66ecc62314115c1e895c238381883363acafd8 /test/asan
parent4658ff5fee0369e08fe69bce90019fad154d9330 (diff)
Notes
Diffstat (limited to 'test/asan')
-rw-r--r--test/asan/TestCases/Linux/allocator_oom_test.cc3
-rw-r--r--test/asan/TestCases/Linux/preinstalled_signal.cc44
-rw-r--r--test/asan/TestCases/Windows/oom.cc2
-rw-r--r--test/asan/TestCases/pr33372.cc39
-rw-r--r--test/asan/lit.cfg1
5 files changed, 67 insertions, 22 deletions
diff --git a/test/asan/TestCases/Linux/allocator_oom_test.cc b/test/asan/TestCases/Linux/allocator_oom_test.cc
index c93e9fe217264..4c696f325803b 100644
--- a/test/asan/TestCases/Linux/allocator_oom_test.cc
+++ b/test/asan/TestCases/Linux/allocator_oom_test.cc
@@ -28,6 +28,9 @@
// RUN: %env_asan_opts=allocator_may_return_null=1 %run %t realloc-after-malloc 2>&1 \
// RUN: | FileCheck %s --check-prefixes=CHECK-MALLOC-REALLOC,CHECK-NULL
+// ASan shadow memory on s390 is too large for this test.
+// UNSUPPORTED: s390
+
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
diff --git a/test/asan/TestCases/Linux/preinstalled_signal.cc b/test/asan/TestCases/Linux/preinstalled_signal.cc
index 40dadf43dc4ec..4d466c21f9440 100644
--- a/test/asan/TestCases/Linux/preinstalled_signal.cc
+++ b/test/asan/TestCases/Linux/preinstalled_signal.cc
@@ -4,11 +4,13 @@
// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=2 not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx -std=c++11 -DTEST_INSTALL_SIG_HANDLER %s -o %t
-// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-HANDLER %s
+// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-HANDLER
+// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=1 not %run %t 2>&1 | FileCheck %s
// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=2 not %run %t 2>&1 | FileCheck %s
// RUN: %clangxx -std=c++11 -DTEST_INSTALL_SIG_ACTION %s -o %t
-// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ACTION %s
+// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=0 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-ACTION
+// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=1 not %run %t 2>&1 | FileCheck %s
// RUN: env LD_PRELOAD=%shared_libasan %env_asan_opts=handle_segv=2 not %run %t 2>&1 | FileCheck %s
// REQUIRES: asan-dynamic-runtime
@@ -51,22 +53,22 @@ int InternalSigaction(int sig, KernelSigaction *act, KernelSigaction *oact) {
return syscall(__NR_rt_sigaction, sig, act, oact, NSIG / 8);
}
-struct KernelSigaction sigact = {};
+struct KernelSigaction pre_asan = {};
static void Init() {
- int res = InternalSigaction(SIGSEGV, nullptr, &sigact);
+ int res = InternalSigaction(SIGSEGV, nullptr, &pre_asan);
assert(res >= 0);
- assert(sigact.handler == SIG_DFL || sigact.handler == SIG_IGN);
+ assert(pre_asan.handler == SIG_DFL || pre_asan.handler == SIG_IGN);
#if defined(TEST_INSTALL_SIG_HANDLER)
- sigact = {};
- sigact.handler = &SigHandler;
- res = InternalSigaction(SIGSEGV, &sigact, nullptr);
+ pre_asan = {};
+ pre_asan.handler = &SigHandler;
+ res = InternalSigaction(SIGSEGV, &pre_asan, nullptr);
assert(res >= 0);
#elif defined(TEST_INSTALL_SIG_ACTION)
- sigact = {};
- sigact.flags = SA_SIGINFO | SA_NODEFER;
- sigact.handler = (__sighandler_t)&SigAction;
- res = InternalSigaction(SIGSEGV, &sigact, nullptr);
+ pre_asan = {};
+ pre_asan.flags = SA_SIGINFO | SA_NODEFER;
+ pre_asan.handler = (__sighandler_t)&SigAction;
+ res = InternalSigaction(SIGSEGV, &pre_asan, nullptr);
assert(res >= 0);
#endif
}
@@ -74,21 +76,21 @@ static void Init() {
__attribute__((section(".preinit_array"), used))
void (*__local_test_preinit)(void) = Init;
-bool ShouldAsanInstallHandlers() {
+bool ExpectUserHandler() {
#if defined(TEST_INSTALL_SIG_HANDLER) || defined(TEST_INSTALL_SIG_ACTION)
- return !strcmp(getenv("ASAN_OPTIONS"), "handle_segv=2");
+ return !strcmp(getenv("ASAN_OPTIONS"), "handle_segv=0");
#endif
- return true;
+ return false;
}
int main(int argc, char *argv[]) {
- KernelSigaction sigact_asan = {};
- InternalSigaction(SIGSEGV, nullptr, &sigact_asan);
+ KernelSigaction post_asan = {};
+ InternalSigaction(SIGSEGV, nullptr, &post_asan);
- assert(sigact_asan.handler != SIG_DFL);
- assert(sigact_asan.handler != SIG_IGN);
- assert(ShouldAsanInstallHandlers() ==
- (sigact_asan.handler != sigact.handler));
+ assert(post_asan.handler != SIG_DFL);
+ assert(post_asan.handler != SIG_IGN);
+ assert(ExpectUserHandler() ==
+ (post_asan.handler == pre_asan.handler));
raise(SIGSEGV);
printf("%s\n", handler);
diff --git a/test/asan/TestCases/Windows/oom.cc b/test/asan/TestCases/Windows/oom.cc
index 59cc7ed0e9d12..71a9c2a759a90 100644
--- a/test/asan/TestCases/Windows/oom.cc
+++ b/test/asan/TestCases/Windows/oom.cc
@@ -8,5 +8,5 @@ int main() {
while (true) {
void *ptr = malloc(200 * 1024 * 1024); // 200MB
}
-// CHECK: failed to allocate
+// CHECK: allocator is terminating the process instead of returning 0
}
diff --git a/test/asan/TestCases/pr33372.cc b/test/asan/TestCases/pr33372.cc
new file mode 100644
index 0000000000000..a4b606e025c9c
--- /dev/null
+++ b/test/asan/TestCases/pr33372.cc
@@ -0,0 +1,39 @@
+// RUN: %clangxx_asan -O0 -std=c++11 %s -o %t && %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O1 -std=c++11 %s -o %t && %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O2 -std=c++11 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+// Test that we do not detect false buffer overflows cased by optimization when
+// when local variable replaced by a smaller global constant.
+// https://bugs.llvm.org/show_bug.cgi?id=33372
+
+#include <stdio.h>
+#include <string.h>
+
+struct A { int x, y, z; };
+struct B { A a; /*gap*/ long b; };
+B *bb;
+
+void test1() {
+ A a1 = {1, 1, 2};
+ B b1 = {a1, 6};
+ bb = new B(b1);
+}
+
+const char KKK[] = {1, 1, 2};
+char bbb[100000];
+
+void test2() {
+ char cc[sizeof(bbb)];
+ memcpy(cc, KKK , sizeof(KKK));
+ memcpy(bbb, cc, sizeof(bbb));
+}
+
+int main(int argc, char *argv[]) {
+ test1();
+ test2();
+ printf("PASSED");
+ return 0;
+}
+
+// CHECK-NOT: ERROR: AddressSanitizer
+// CHECK: PASSED
diff --git a/test/asan/lit.cfg b/test/asan/lit.cfg
index 063c33b02697d..e25dd297aa3b0 100644
--- a/test/asan/lit.cfg
+++ b/test/asan/lit.cfg
@@ -114,6 +114,7 @@ asan_lit_source_dir = get_required_attr(config, "asan_lit_source_dir")
if config.android == "1":
config.available_features.add('android')
compile_wrapper = os.path.join(asan_lit_source_dir, "android_commands", "android_compile.py") + " "
+ config.compile_wrapper = compile_wrapper
else:
config.available_features.add('not-android')