1 | // RUN: %clang_cl_asan %Od %p/dll_host.cpp %Fe%t |
2 | // RUN: %clang_cl_asan %LD %Od %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(f: &memcpy, a: buff2, b: buff1, c: 5); |
18 | if (buff1[2] != buff2[2]) |
19 | return 2; |
20 | printf(format: "Initial test OK\n" ); |
21 | fflush(stream: 0); |
22 | // CHECK: Initial test OK |
23 | |
24 | call_memcpy(f: &memcpy, a: buff2, b: buff1, c: 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: mem{{.*}} |
28 | // CHECK-NEXT: call_memcpy |
29 | // CHECK-NEXT: test_function {{.*}}dll_intercept_memcpy_indirect.cpp:[[@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.cpp |
32 | // CHECK: 'buff2'{{.*}} <== Memory access at offset {{.*}} overflows this variable |
33 | return 0; |
34 | } |
35 | |