1// Check that stores in signal handlers are not recorded in origin history.
2//
3// Origin tracking uses ChainedOriginDepot that is not async signal safe, so we
4// do not track origins inside signal handlers.
5//
6// RUN: %clangxx_dfsan -gmlt -mllvm -dfsan-track-origins=1 -mllvm -dfsan-fast-16-labels=true %s -o %t && \
7// RUN: %run %t >%t.out 2>&1
8// RUN: FileCheck %s < %t.out
9//
10// RUN: %clangxx_dfsan -gmlt -mllvm -dfsan-instrument-with-call-threshold=0 -mllvm -dfsan-track-origins=1 -mllvm -dfsan-fast-16-labels=true %s -o %t && \
11// RUN: %run %t >%t.out 2>&1
12// RUN: FileCheck %s < %t.out
13//
14// REQUIRES: x86_64-target-arch
15
16#include <sanitizer/dfsan_interface.h>
17
18#include <signal.h>
19#include <string.h>
20#include <sys/types.h>
21#include <unistd.h>
22
23int x, y, u;
24
25void SignalHandler(int signo) {
26 y = x;
27 memcpy(&u, &y, sizeof(int));
28}
29
30int main(int argc, char *argv[]) {
31 int z = 0;
32 dfsan_set_label(8, &z, sizeof(z));
33 x = z;
34
35 signal(SIGHUP, SignalHandler);
36 kill(getpid(), SIGHUP);
37 signal(SIGHUP, SIG_DFL);
38
39 dfsan_print_origin_trace(&u, nullptr);
40 return 0;
41}
42
43// CHECK: Taint value 0x8 {{.*}} origin tracking ()
44// CHECK: Origin value: {{.*}}, Taint value was stored to memory at
45// CHECK-NOT: {{.*}} in dfs$SignalHandler {{.*}}origin_with_signals.cpp{{.*}}
46
47// CHECK: #0 {{.*}} in main {{.*}}origin_with_signals.cpp:[[@LINE-14]]
48
49// CHECK: Origin value: {{.*}}, Taint value was created at
50// CHECK: #0 {{.*}} in main {{.*}}origin_with_signals.cpp:[[@LINE-18]]
51