1 // RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t 2 // RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll 3 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s 4 5 #include <stdio.h> 6 #include <string.h> 7 8 void call_memcpy(void* (*f)(void *, const void *, size_t), 9 void *a, const void *b, size_t c) { 10 f(a, b, c); 11 } 12 13 extern "C" __declspec(dllexport) 14 int test_function() { 15 char buff1[6] = "Hello", buff2[5]; 16 17 call_memcpy(&memcpy, buff2, buff1, 5); 18 if (buff1[2] != buff2[2]) 19 return 2; 20 printf("Initial test OK\n"); 21 fflush(0); 22 // CHECK: Initial test OK 23 24 call_memcpy(&memcpy, buff2, buff1, 6); 25 // CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]] 26 // CHECK: WRITE of size 6 at [[ADDR]] thread T0 27 // CHECK-NEXT: __asan_memcpy 28 // CHECK-NEXT: call_memcpy 29 // CHECK-NEXT: test_function {{.*}}dll_intercept_memcpy_indirect.cc:[[@LINE-5]] 30 // CHECK: Address [[ADDR]] is located in stack of thread T0 at offset {{.*}} in frame 31 // CHECK-NEXT: test_function {{.*}}dll_intercept_memcpy_indirect.cc 32 // CHECK: 'buff2' <== Memory access at offset {{.*}} overflows this variable 33 return 0; 34 } 35