1 | // RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 %s -o %t && \ |
2 | // RUN: %run %t 2>&1 | FileCheck %s |
3 | |
4 | #include <assert.h> |
5 | #include <sanitizer/dfsan_interface.h> |
6 | #include <stdio.h> |
7 | |
8 | __attribute__((noinline)) uint64_t foo(uint64_t a, uint64_t b) { return a + b; } |
9 | |
10 | int main(int argc, char *argv[]) { |
11 | uint64_t a = 10; |
12 | uint64_t b = 20; |
13 | dfsan_set_label(label: 8, addr: &a, size: sizeof(a)); |
14 | uint64_t c = foo(a, b); |
15 | |
16 | dfsan_origin c_orig = dfsan_get_origin(data: c); |
17 | fprintf(stderr, format: "c_orig 0x%x\n" , c_orig); |
18 | // CHECK: c_orig 0x[[#%x,C_ORIG:]] |
19 | assert(c_orig != 0); |
20 | dfsan_print_origin_id_trace(origin: c_orig); |
21 | // CHECK: Origin value: 0x[[#%x,C_ORIG]], Taint value was created at |
22 | |
23 | uint64_t d[4] = {1, 2, 3, c}; |
24 | dfsan_origin d_orig = dfsan_read_origin_of_first_taint(addr: d, size: sizeof(d)); |
25 | fprintf(stderr, format: "d_orig 0x%x\n" , d_orig); |
26 | // CHECK: d_orig 0x[[#%x,D_ORIG:]] |
27 | assert(d_orig != 0); |
28 | dfsan_print_origin_id_trace(origin: d_orig); |
29 | // CHECK: Origin value: 0x[[#%x,D_ORIG]], Taint value was stored to memory at |
30 | // CHECK: Origin value: 0x[[#%x,C_ORIG]], Taint value was created at |
31 | return 0; |
32 | } |
33 | |