xref: /aosp_15_r20/external/compiler-rt/test/asan/TestCases/Posix/interception-in-shared-lib-test.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // Check that memset() call from a shared library gets intercepted.
2*7c3d14c8STreehugger Robot 
3*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O0 %s -DSHARED_LIB \
4*7c3d14c8STreehugger Robot // RUN:     -shared -o %dynamiclib -fPIC %ld_flags_rpath_so
5*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O0 %s -o %t %ld_flags_rpath_exe && \
6*7c3d14c8STreehugger Robot // RUN:     not %run %t 2>&1 | FileCheck %s
7*7c3d14c8STreehugger Robot 
8*7c3d14c8STreehugger Robot #include <stdio.h>
9*7c3d14c8STreehugger Robot #include <string.h>
10*7c3d14c8STreehugger Robot 
11*7c3d14c8STreehugger Robot #if defined(SHARED_LIB)
12*7c3d14c8STreehugger Robot extern "C"
my_memset(void * p,size_t sz)13*7c3d14c8STreehugger Robot void my_memset(void *p, size_t sz) {
14*7c3d14c8STreehugger Robot   memset(p, 0, sz);
15*7c3d14c8STreehugger Robot }
16*7c3d14c8STreehugger Robot #else
17*7c3d14c8STreehugger Robot extern "C" void my_memset(void *p, size_t sz);
18*7c3d14c8STreehugger Robot 
main(int argc,char * argv[])19*7c3d14c8STreehugger Robot int main(int argc, char *argv[]) {
20*7c3d14c8STreehugger Robot   char buf[10];
21*7c3d14c8STreehugger Robot   my_memset(buf, 11);
22*7c3d14c8STreehugger Robot   // CHECK: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}}
23*7c3d14c8STreehugger Robot   // CHECK: {{WRITE of size 11 at 0x.* thread T0}}
24*7c3d14c8STreehugger Robot   // CHECK: {{0x.* in my_memset .*interception-in-shared-lib-test.cc:}}[[@LINE-10]]
25*7c3d14c8STreehugger Robot   return 0;
26*7c3d14c8STreehugger Robot }
27*7c3d14c8STreehugger Robot #endif
28