1 // RUN: %clangxx_msan %s -std=c++11 -DSENDMSG -DPOISONFD -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
2 // RUN: %clangxx_msan %s -std=c++11 -DSENDMSG -DPOISONCRED -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
3 // RUN: %clangxx_msan %s -std=c++11 -DSENDMSG -DPOISONLEN -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
4 // RUN: %clangxx_msan %s -std=c++11 -DSENDMSG -DPOISONLEVEL -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
5 // RUN: %clangxx_msan %s -std=c++11 -DSENDMSG -DPOISONTYPE -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
6 // RUN: %clangxx_msan %s -std=c++11 -DSENDMSG -DPOISONLEN2 -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
7 // RUN: %clangxx_msan %s -std=c++11 -DSENDMSG -DPOISONLEVEL2 -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
8 // RUN: %clangxx_msan %s -std=c++11 -DSENDMSG -DPOISONTYPE2 -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
9 // RUN: %clangxx_msan %s -std=c++11 -DSENDMSG -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE
11 // UNSUPPORTED: android
20 #include <sys/types.h>
21 #include <sys/socket.h>
23 #include <sanitizer/msan_interface.h>
25 const int kBufSize
= 10;
29 char buf
[kBufSize
] = {0};
30 pthread_t client_thread
;
31 struct sockaddr_un serveraddr
;
34 ret
= socketpair(AF_UNIX
, SOCK_STREAM
, 0, sock
);
39 struct iovec iov
[] = {{buf
, 10}};
40 struct msghdr msg
= {0};
45 static const int kNumFds
= 3;
46 char controlbuf
[CMSG_SPACE(kNumFds
* sizeof(int)) +
47 CMSG_SPACE(sizeof(struct ucred
))];
48 msg
.msg_control
= &controlbuf
;
49 msg
.msg_controllen
= sizeof(controlbuf
);
51 struct cmsghdr
*cmsg
= (struct cmsghdr
*)&controlbuf
;
57 __msan_poison(&myfds
[1], sizeof(int));
59 cmsg
->cmsg_level
= SOL_SOCKET
;
60 cmsg
->cmsg_type
= SCM_RIGHTS
;
61 cmsg
->cmsg_len
= CMSG_LEN(kNumFds
* sizeof(int));
62 memcpy(CMSG_DATA(cmsg
), myfds
, kNumFds
* sizeof(int));
64 __msan_poison(&cmsg
->cmsg_level
, sizeof(cmsg
->cmsg_level
));
67 __msan_poison(&cmsg
->cmsg_type
, sizeof(cmsg
->cmsg_type
));
70 __msan_poison(&cmsg
->cmsg_len
, sizeof(cmsg
->cmsg_len
));
73 cmsg
= (struct cmsghdr
*)(&controlbuf
[CMSG_SPACE(kNumFds
* sizeof(int))]);
75 struct ucred cred
= {getpid(), getuid(), getgid()};
77 __msan_poison(&cred
.uid
, sizeof(cred
.uid
));
79 cmsg
->cmsg_level
= SOL_SOCKET
;
80 cmsg
->cmsg_type
= SCM_CREDENTIALS
;
81 cmsg
->cmsg_len
= CMSG_LEN(sizeof(struct ucred
));
82 memcpy(CMSG_DATA(cmsg
), &cred
, sizeof(struct ucred
));
84 __msan_poison(&cmsg
->cmsg_level
, sizeof(cmsg
->cmsg_level
));
87 __msan_poison(&cmsg
->cmsg_type
, sizeof(cmsg
->cmsg_type
));
90 __msan_poison(&cmsg
->cmsg_len
, sizeof(cmsg
->cmsg_len
));
93 ret
= sendmsg(sockfd
, &msg
, 0);
94 // SENDMSG: MemorySanitizer: use-of-uninitialized-value
95 if (ret
== -1) printf("%d: %s\n", errno
, strerror(errno
));
98 fprintf(stderr
, "== done\n");