1 | // RUN: %clang_dfsan -DUSE_SIGNAL_ACTION -Wno-error=int-conversion %s -o %t && %run %t |
2 | // RUN: %clang_dfsan -Wno-error=int-conversion %s -o %t && %run %t |
3 | |
4 | #include <sanitizer/dfsan_interface.h> |
5 | |
6 | #include <assert.h> |
7 | #include <signal.h> |
8 | #include <string.h> |
9 | #include <sys/types.h> |
10 | #include <unistd.h> |
11 | |
12 | volatile int x; |
13 | volatile int z = 1; |
14 | |
15 | void SignalHandler(int signo) { |
16 | assert(dfsan_get_label(signo) == 0); |
17 | x = z; |
18 | } |
19 | |
20 | void SignalAction(int signo, siginfo_t *si, void *uc) { |
21 | assert(dfsan_get_label(signo) == 0); |
22 | assert(dfsan_get_label(si) == 0); |
23 | assert(dfsan_get_label(uc) == 0); |
24 | assert(0 == dfsan_read_label(si, sizeof(*si))); |
25 | assert(0 == dfsan_read_label(uc, sizeof(ucontext_t))); |
26 | x = z; |
27 | } |
28 | |
29 | int main(int argc, char *argv[]) { |
30 | dfsan_set_label(label: 8, addr: (void *)&z, size: sizeof(z)); |
31 | |
32 | struct sigaction sa = {}; |
33 | #ifdef USE_SIGNAL_ACTION |
34 | sa.sa_flags = SA_SIGINFO; |
35 | sa.sa_sigaction = SignalAction; |
36 | #else |
37 | sa.sa_handler = SignalHandler; |
38 | #endif |
39 | int r = sigaction(SIGHUP, act: &sa, NULL); |
40 | assert(dfsan_get_label(r) == 0); |
41 | |
42 | kill(pid: getpid(), SIGHUP); |
43 | signal(SIGHUP, SIG_DFL); |
44 | |
45 | assert(x == 1); |
46 | |
47 | return 0; |
48 | } |
49 | |