1 | // RUN: %clang_dfsan -gmlt -DOFFSET=0 -mllvm -dfsan-track-origins=1 %s -o %t && \ |
2 | // RUN: %run %t >%t.out 2>&1 |
3 | // RUN: FileCheck %s --check-prefix=CHECK0 < %t.out |
4 | // |
5 | // RUN: %clang_dfsan -gmlt -DOFFSET=10 -mllvm -dfsan-track-origins=1 %s -o %t && \ |
6 | // RUN: %run %t >%t.out 2>&1 |
7 | // RUN: FileCheck %s --check-prefix=CHECK10 < %t.out |
8 | |
9 | #include <sanitizer/dfsan_interface.h> |
10 | |
11 | #include <string.h> |
12 | |
13 | int xx[10000]; |
14 | int yy[10000]; |
15 | volatile int idx = 30; |
16 | |
17 | __attribute__((noinline)) |
18 | void fn_g(int a, int b) { |
19 | xx[idx] = a; xx[idx + 10] = b; |
20 | } |
21 | |
22 | __attribute__((noinline)) |
23 | void fn_f(int a, int b) { |
24 | fn_g(a, b); |
25 | } |
26 | |
27 | __attribute__((noinline)) |
28 | void fn_h() { |
29 | memcpy(dest: &yy, src: &xx, n: sizeof(xx)); |
30 | } |
31 | |
32 | int main(int argc, char *argv[]) { |
33 | int volatile z1 = 0; |
34 | int volatile z2 = 0; |
35 | dfsan_set_label(label: 8, addr: (void *)&z1, size: sizeof(z1)); |
36 | dfsan_set_label(label: 16, addr: (void *)&z2, size: sizeof(z2)); |
37 | fn_f(a: z1, b: z2); |
38 | fn_h(); |
39 | dfsan_print_origin_trace(&yy[idx + OFFSET], NULL); |
40 | return 0; |
41 | } |
42 | |
43 | // CHECK0: Taint value 0x8 {{.*}} origin tracking () |
44 | // CHECK0: Origin value: {{.*}}, Taint value was stored to memory at |
45 | // CHECK0: #0 {{.*}} in fn_h.dfsan {{.*}}origin_memcpy.c:[[@LINE-16]] |
46 | // CHECK0: #1 {{.*}} in main {{.*}}origin_memcpy.c:[[@LINE-8]] |
47 | |
48 | // CHECK0: Origin value: {{.*}}, Taint value was stored to memory at |
49 | // CHECK0: #0 {{.*}} in fn_g.dfsan {{.*}}origin_memcpy.c:[[@LINE-30]] |
50 | // CHECK0: #1 {{.*}} in fn_f.dfsan {{.*}}origin_memcpy.c:[[@LINE-26]] |
51 | // CHECK0: #2 {{.*}} in main {{.*}}origin_memcpy.c:[[@LINE-14]] |
52 | |
53 | // CHECK0: Origin value: {{.*}}, Taint value was created at |
54 | // CHECK0: #0 {{.*}} in main {{.*}}origin_memcpy.c:[[@LINE-19]] |
55 | |
56 | // CHECK10: Taint value 0x10 {{.*}} origin tracking () |
57 | // CHECK10: Origin value: {{.*}}, Taint value was stored to memory at |
58 | // CHECK10: #0 {{.*}} in fn_h.dfsan {{.*}}origin_memcpy.c:[[@LINE-29]] |
59 | // CHECK10: #1 {{.*}} in main {{.*}}origin_memcpy.c:[[@LINE-21]] |
60 | |
61 | // CHECK10: Origin value: {{.*}}, Taint value was stored to memory at |
62 | // CHECK10: #0 {{.*}} in fn_g.dfsan {{.*}}origin_memcpy.c:[[@LINE-43]] |
63 | // CHECK10: #1 {{.*}} in fn_f.dfsan {{.*}}origin_memcpy.c:[[@LINE-39]] |
64 | // CHECK10: #2 {{.*}} in main {{.*}}origin_memcpy.c:[[@LINE-27]] |
65 | |
66 | // CHECK10: Origin value: {{.*}}, Taint value was created at |
67 | // CHECK10: #0 {{.*}} in main {{.*}}origin_memcpy.c:[[@LINE-31]] |
68 | |