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 %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 %s -o %t && \
11// RUN: %run %t >%t.out 2>&1
12// RUN: FileCheck %s < %t.out
13
14#include <sanitizer/dfsan_interface.h>
15
16#include <signal.h>
17#include <string.h>
18#include <sys/types.h>
19#include <unistd.h>
20
21int x, y, u;
22
23void SignalHandler(int signo) {
24 y = x;
25 memcpy(dest: &u, src: &y, n: sizeof(int));
26}
27
28int main(int argc, char *argv[]) {
29 int z = 0;
30 dfsan_set_label(label: 8, addr: &z, size: sizeof(z));
31 x = z;
32
33 signal(SIGHUP, handler: SignalHandler);
34 kill(pid: getpid(), SIGHUP);
35 signal(SIGHUP, SIG_DFL);
36
37 dfsan_print_origin_trace(addr: &u, description: nullptr);
38 return 0;
39}
40
41// CHECK: Taint value 0x8 {{.*}} origin tracking ()
42// CHECK: Origin value: {{.*}}, Taint value was stored to memory at
43// CHECK-NOT: {{.*}} in SignalHandler.dfsan {{.*}}origin_with_signals.cpp{{.*}}
44
45// CHECK: #0 {{.*}} in main {{.*}}origin_with_signals.cpp:[[@LINE-14]]
46
47// CHECK: Origin value: {{.*}}, Taint value was created at
48// CHECK: #0 {{.*}} in main {{.*}}origin_with_signals.cpp:[[@LINE-18]]
49

source code of compiler-rt/test/dfsan/origin_with_signals.cpp