• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Check that memset() call from a shared library gets intercepted.
2 // Please always keep this file in sync with
3 // ../Linux/interception-in-shared-lib-test.cc.
4 
5 // RUN: %clangxx_asan -O0 %s -DSHARED_LIB \
6 // RUN:     -shared -o %T/libinterception-in-shared-lib-test.so \
7 // RUN:     -fPIC
8 // TODO(glider): figure out how to set rpath in a more portable way and unite
9 // this test with ../Linux/interception-in-shared-lib-test.cc.
10 // RUN: %clangxx_asan -O0 %s -o %t -Wl,-rpath,@executable-path -L%T -linterception-in-shared-lib-test && \
11 // RUN:     not %run %t 2>&1 | FileCheck %s
12 
13 #include <stdio.h>
14 #include <string.h>
15 
16 #if defined(SHARED_LIB)
17 extern "C"
my_memset(void * p,size_t sz)18 void my_memset(void *p, size_t sz) {
19   memset(p, 0, sz);
20 }
21 #else
22 extern "C" void my_memset(void *p, size_t sz);
23 
main(int argc,char * argv[])24 int main(int argc, char *argv[]) {
25   char buf[10];
26   my_memset(buf, 11);
27   // CHECK: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}}
28   // CHECK: {{WRITE of size 11 at 0x.* thread T0}}
29   // CHECK: {{0x.* in my_memset .*interception-in-shared-lib-test.cc:19}}
30   return 0;
31 }
32 #endif
33