From 4bf7a268e0fd0fb493e1b05d6e37771ff98758a8 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Mon, 24 Feb 2014 14:31:28 +0000 Subject: [PATCH] [asan] Add a test for interceptors in shared libraries. llvm-svn: 202037 --- .../SharedLibs/shared-lib-test-so.cc | 6 ++++++ .../TestCases/asan-symbolize-sanity-test.cc | 2 +- .../interception-in-shared-lib-test.cc | 21 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 compiler-rt/test/asan/TestCases/interception-in-shared-lib-test.cc diff --git a/compiler-rt/test/asan/TestCases/SharedLibs/shared-lib-test-so.cc b/compiler-rt/test/asan/TestCases/SharedLibs/shared-lib-test-so.cc index 6ef565ce47b3..6aedc93be349 100644 --- a/compiler-rt/test/asan/TestCases/SharedLibs/shared-lib-test-so.cc +++ b/compiler-rt/test/asan/TestCases/SharedLibs/shared-lib-test-so.cc @@ -11,6 +11,7 @@ // //===----------------------------------------------------------------------===// #include +#include int pad[10]; int GLOB[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -24,3 +25,8 @@ extern "C" void inc2(int *a, int index) { a[index]++; } + +extern "C" +void my_memset(void *p, size_t sz) { + memset(p, 0, sz); +} diff --git a/compiler-rt/test/asan/TestCases/asan-symbolize-sanity-test.cc b/compiler-rt/test/asan/TestCases/asan-symbolize-sanity-test.cc index 0efe245bb6b5..991dcec97a10 100644 --- a/compiler-rt/test/asan/TestCases/asan-symbolize-sanity-test.cc +++ b/compiler-rt/test/asan/TestCases/asan-symbolize-sanity-test.cc @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) { inc2(array, -1); // BOOM // CHECK: ERROR: AddressSanitizer: heap-buffer-overflow // CHECK: READ of size 4 at 0x{{.*}} - // CHECK: #0 {{.*}} in inc2 {{.*}}shared-lib-test-so.cc:25 + // CHECK: #0 {{.*}} in inc2 {{.*}}shared-lib-test-so.cc:26 // CHECK: #1 {{.*}} in main {{.*}}asan-symbolize-sanity-test.cc:[[@LINE-4]] // CHECK: allocated by thread T{{.*}} here: // CHECK: #{{.*}} in {{(wrap_|__interceptor_)?}}malloc diff --git a/compiler-rt/test/asan/TestCases/interception-in-shared-lib-test.cc b/compiler-rt/test/asan/TestCases/interception-in-shared-lib-test.cc new file mode 100644 index 000000000000..27fce453c454 --- /dev/null +++ b/compiler-rt/test/asan/TestCases/interception-in-shared-lib-test.cc @@ -0,0 +1,21 @@ +// Check that memset() call from a shared library gets intercepted. + +// RUN: %clangxx_asan -O0 %p/SharedLibs/shared-lib-test-so.cc \ +// RUN: -shared -o %T/libinterception-in-shared-lib-test.so \ +// RUN: -fPIC -Wl,--soname,libinterception-in-shared-lib-test.so +// RUN: %clangxx_asan -O0 %s -o %t -Wl,-R,\$ORIGIN -L%T -linterception-in-shared-lib-test && \ +// RUN: not %t 2>&1 | FileCheck %s + +#include +#include + +extern "C" void my_memset(void *p, size_t sz); + +int main(int argc, char *argv[]) { + char buf[10]; + my_memset(buf, 11); + // CHECK: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}} + // CHECK: {{WRITE of size 11 at 0x.* thread T0}} + // CHECK: {{ #0 0x.* in my_memset .*shared-lib-test-so.cc:31}} + return 0; +}