llvm-project
48 строк · 1.4 Кб
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) {24y = x;25memcpy(&u, &y, sizeof(int));26}
27
28int main(int argc, char *argv[]) {29int z = 0;30dfsan_set_label(8, &z, sizeof(z));31x = z;32
33signal(SIGHUP, SignalHandler);34kill(getpid(), SIGHUP);35signal(SIGHUP, SIG_DFL);36
37dfsan_print_origin_trace(&u, nullptr);38return 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