1// RUN: %clangxx_msan -std=c++11 -O0 -g %s -o %t
2// RUN: %run %t __
3// RUN: not %run %t A_ 2>&1 | FileCheck %s
4// RUN: not %run %t AH 2>&1 | FileCheck %s
5// RUN: not %run %t B_ 2>&1 | FileCheck %s
6// RUN: not %run %t BH 2>&1 | FileCheck %s
7// RUN: not %run %t C_ 2>&1 | FileCheck %s
8// RUN: not %run %t CH 2>&1 | FileCheck %s
9
10#include <assert.h>
11#include <signal.h>
12#include <string.h>
13#include <sys/time.h>
14#include <unistd.h>
15
16#include <sanitizer/msan_interface.h>
17
18void handler(int) {}
19void action(int, siginfo_t *, void *) {}
20
21int main(int argc, char **argv) {
22 char T = argv[1][0];
23 char H = argv[1][1];
24 struct sigaction sa;
25 memset(s: &sa, c: 0, n: sizeof(sa));
26 if (H == 'H') {
27 sa.sa_handler = handler;
28 } else {
29 sa.sa_sigaction = action;
30 sa.sa_flags = SA_SIGINFO;
31 }
32
33 if (T == 'A') {
34 if (H == 'H')
35 __msan_poison(a: &sa.sa_handler, size: sizeof(sa.sa_handler));
36 else
37 __msan_poison(a: &sa.sa_sigaction, size: sizeof(sa.sa_sigaction));
38 }
39 if (T == 'B')
40 __msan_poison(a: &sa.sa_flags, size: sizeof(sa.sa_flags));
41 if (T == 'C')
42 __msan_poison(a: &sa.sa_mask, size: sizeof(sa.sa_mask));
43 // CHECK: use-of-uninitialized-value
44 int res = sigaction(SIGUSR1, act: &sa, oact: nullptr);
45 assert(res == 0);
46 return 0;
47}
48

source code of compiler-rt/test/msan/sigaction.cpp