1 // RUN: %clangxx_msan -O0 -g %s -o %t && %run %t
2 // RUN: %clangxx_msan -O3 -g %s -o %t && %run %t
3
4 // RUN: %clangxx_msan -DPOSITIVE -O0 -g %s -o %t && not %run %t 2>&1 | FileCheck %s
5 // RUN: %clangxx_msan -DPOSITIVE -O3 -g %s -o %t && not %run %t 2>&1 | FileCheck %s
6
7 #include <assert.h>
8 #include <stdlib.h>
9 #include <net/if.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <sys/ioctl.h>
13 #include <sys/socket.h>
14 #include <unistd.h>
15
main(int argc,char ** argv)16 int main(int argc, char **argv) {
17 int fd = socket(AF_INET, SOCK_STREAM, 0);
18
19 struct ifreq ifreqs[20];
20 struct ifconf ifc;
21 ifc.ifc_ifcu.ifcu_req = ifreqs;
22 #ifndef POSITIVE
23 ifc.ifc_len = sizeof(ifreqs);
24 #endif
25 int res = ioctl(fd, SIOCGIFCONF, (void *)&ifc);
26 // CHECK: Uninitialized bytes in ioctl{{.*}} at offset 0 inside [0x{{.*}}, 4)
27 // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
28 // CHECK: #{{.*}} in main {{.*}}ioctl_custom.cc:[[@LINE-3]]
29 assert(res == 0);
30 for (int i = 0; i < ifc.ifc_len / sizeof(*ifc.ifc_ifcu.ifcu_req); ++i)
31 printf("%d %zu %s\n", i, strlen(ifreqs[i].ifr_name), ifreqs[i].ifr_name);
32 return 0;
33 }
34