llvm-project
32 строки · 1.1 Кб
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
10int main(int argc, char *argv[]) {11uint64_t a = 10;12uint64_t b = 20;13dfsan_set_label(8, &a, sizeof(a));14uint64_t c = foo(a, b);15
16dfsan_origin c_orig = dfsan_get_origin(c);17fprintf(stderr, "c_orig 0x%x\n", c_orig);18// CHECK: c_orig 0x[[#%x,C_ORIG:]]19assert(c_orig != 0);20dfsan_print_origin_id_trace(c_orig);21// CHECK: Origin value: 0x[[#%x,C_ORIG]], Taint value was created at22
23uint64_t d[4] = {1, 2, 3, c};24dfsan_origin d_orig = dfsan_read_origin_of_first_taint(d, sizeof(d));25fprintf(stderr, "d_orig 0x%x\n", d_orig);26// CHECK: d_orig 0x[[#%x,D_ORIG:]]27assert(d_orig != 0);28dfsan_print_origin_id_trace(d_orig);29// CHECK: Origin value: 0x[[#%x,D_ORIG]], Taint value was stored to memory at30// CHECK: Origin value: 0x[[#%x,C_ORIG]], Taint value was created at31return 0;32}
33