1 // RUN: %clangxx_msan %s -DSEND -DPOISON -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SEND 2 // RUN: %clangxx_msan %s -DSENDTO -DPOISON -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDTO 3 // RUN: %clangxx_msan %s -DSENDMSG -DPOISON -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG 4 5 // RUN: %clangxx_msan %s -DSEND -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE 6 // RUN: %clangxx_msan %s -DSENDTO -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE 7 // RUN: %clangxx_msan %s -DSENDMSG -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE 8 9 // RUN: %clangxx_msan %s -DSEND -DPOISON -o %t && \ 10 // RUN: MSAN_OPTIONS=intercept_send=0 %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE 11 // RUN: %clangxx_msan %s -DSENDTO -DPOISON -o %t && \ 12 // RUN: MSAN_OPTIONS=intercept_send=0 %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE 13 // RUN: %clangxx_msan %s -DSENDMSG -DPOISON -o %t && \ 14 // RUN: MSAN_OPTIONS=intercept_send=0 %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE 15 16 // UNSUPPORTED: android 17 18 #include <assert.h> 19 #include <stdio.h> 20 #include <unistd.h> 21 #include <stdlib.h> 22 #include <string.h> 23 #include <netdb.h> 24 #include <sys/types.h> 25 #include <sys/socket.h> 26 #include <sanitizer/msan_interface.h> 27 28 const int kBufSize = 10; 29 int sockfd; 30 31 int main() { 32 int ret; 33 char buf[kBufSize] = {0}; 34 pthread_t client_thread; 35 struct sockaddr_in serveraddr; 36 37 sockfd = socket(AF_INET, SOCK_DGRAM, 0); 38 39 memset(&serveraddr, 0, sizeof(serveraddr)); 40 serveraddr.sin_family = AF_INET; 41 serveraddr.sin_addr.s_addr = htonl(INADDR_ANY); 42 serveraddr.sin_port = 0; 43 44 bind(sockfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)); 45 socklen_t addrlen = sizeof(serveraddr); 46 getsockname(sockfd, (struct sockaddr *)&serveraddr, &addrlen); 47 48 #if defined(POISON) 49 __msan_poison(buf + 7, 1); 50 #endif 51 52 #if defined(SENDMSG) 53 struct iovec iov[2] = {{buf, 5}, {buf + 5, 5}}; 54 struct msghdr msg; 55 msg.msg_name = &serveraddr; 56 msg.msg_namelen = addrlen; 57 msg.msg_iov = iov; 58 msg.msg_iovlen = 2; 59 msg.msg_control = 0; 60 msg.msg_controllen = 0; 61 msg.msg_flags = 0; 62 #endif 63 64 #if defined(SEND) 65 ret = connect(sockfd, (struct sockaddr *)&serveraddr, addrlen); 66 assert(ret == 0); 67 ret = send(sockfd, buf, kBufSize, 0); 68 // SEND: Uninitialized bytes in __interceptor_send at offset 7 inside [{{.*}}, 10) 69 assert(ret > 0); 70 #elif defined(SENDTO) 71 ret = 72 sendto(sockfd, buf, kBufSize, 0, (struct sockaddr *)&serveraddr, addrlen); 73 // SENDTO: Uninitialized bytes in __interceptor_sendto at offset 7 inside [{{.*}}, 10) 74 assert(ret > 0); 75 #elif defined(SENDMSG) 76 ret = sendmsg(sockfd, &msg, 0); 77 // SENDMSG: Uninitialized bytes in {{.*}} at offset 2 inside [{{.*}}, 5) 78 assert(ret > 0); 79 #endif 80 fprintf(stderr, "== done\n"); 81 // NEGATIVE: == done 82 return 0; 83 } 84