17c9150579ed0278492f51cc8434b1d63a44b9bd1Pirama Arumuga Nainar// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t 27c9150579ed0278492f51cc8434b1d63a44b9bd1Pirama Arumuga Nainar// RUN: %clangxx_msan -O3 -g %s -o %t && %run %t 34757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov 47c9150579ed0278492f51cc8434b1d63a44b9bd1Pirama Arumuga Nainar// RUN: %clangxx_msan -DPOSITIVE -O0 -g %s -o %t && not %run %t 2>&1 | FileCheck %s 57c9150579ed0278492f51cc8434b1d63a44b9bd1Pirama Arumuga Nainar// RUN: %clangxx_msan -DPOSITIVE -O3 -g %s -o %t && not %run %t 2>&1 | FileCheck %s 64757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov 74757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov#include <assert.h> 84757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov#include <stdlib.h> 94757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov#include <net/if.h> 104757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov#include <stdio.h> 114757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov#include <string.h> 124757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov#include <sys/ioctl.h> 134757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov#include <sys/socket.h> 144757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov#include <unistd.h> 154757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov 164757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanovint main(int argc, char **argv) { 174757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov int fd = socket(AF_INET, SOCK_STREAM, 0); 184757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov 194757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov struct ifreq ifreqs[20]; 204757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov struct ifconf ifc; 214757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov ifc.ifc_ifcu.ifcu_req = ifreqs; 224757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov#ifndef POSITIVE 234757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov ifc.ifc_len = sizeof(ifreqs); 244757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov#endif 254757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov int res = ioctl(fd, SIOCGIFCONF, (void *)&ifc); 262d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines // CHECK: Uninitialized bytes in ioctl{{.*}} at offset 0 inside [0x{{.*}}, 4) 274757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value 284757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov // CHECK: #{{.*}} in main {{.*}}ioctl_custom.cc:[[@LINE-3]] 294757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov assert(res == 0); 304757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov for (int i = 0; i < ifc.ifc_len / sizeof(*ifc.ifc_ifcu.ifcu_req); ++i) 314757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov printf("%d %zu %s\n", i, strlen(ifreqs[i].ifr_name), ifreqs[i].ifr_name); 324757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov return 0; 334757c47ba7356aec3a7d49e5e929c19159d75a01Evgeniy Stepanov} 34