--- /dev/null
+// RUN: %clangxx_msan -m64 -O0 -g %s -o %t && %t
+// RUN: %clangxx_msan -m64 -O3 -g %s -o %t && %t
+
+// RUN: %clangxx_msan -DPOSITIVE -m64 -O0 -g %s -o %t && %t 2>&1 | FileCheck %s
+// RUN: %clangxx_msan -DPOSITIVE -m64 -O3 -g %s -o %t && %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <stdlib.h>
+#include <net/if.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+int main(int argc, char **argv) {
+ int fd = socket(AF_INET, SOCK_STREAM, 0);
+
+ struct ifreq ifreqs[20];
+ struct ifconf ifc;
+ ifc.ifc_ifcu.ifcu_req = ifreqs;
+#ifndef POSITIVE
+ ifc.ifc_len = sizeof(ifreqs);
+#endif
+ int res = ioctl(fd, SIOCGIFCONF, (void *)&ifc);
+ // CHECK: UMR in ioctl{{.*}} at offset 0
+ // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
+ // CHECK: #{{.*}} in main {{.*}}ioctl_custom.cc:[[@LINE-3]]
+ assert(res == 0);
+ for (int i = 0; i < ifc.ifc_len / sizeof(*ifc.ifc_ifcu.ifcu_req); ++i)
+ printf("%d %zu %s\n", i, strlen(ifreqs[i].ifr_name), ifreqs[i].ifr_name);
+ return 0;
+}
_(0x00008903, WRITE, sizeof(int)); // FIOGETOWN
_(0x00008904, WRITE, sizeof(int)); // SIOCGPGRP
_(0x00008905, WRITE, sizeof(int)); // SIOCATMAR
- _(0x00008912, WRITE, struct_ifconf_sz); // SIOCGIFCONF
+ _(0x00008912, CUSTOM, 0); // SIOCGIFCONF
_(0x00008913, WRITE, struct_ifreq_sz); // SIOCGIFFLAGS
_(0x00008914, READ, struct_ifreq_sz); // SIOCSIFFLAGS
_(0x00008915, WRITE, struct_ifreq_sz); // SIOCGIFADDR
COMMON_INTERCEPTOR_READ_RANGE(ctx, arg, desc->size);
if (desc->type != ioctl_desc::CUSTOM)
return;
- // FIXME: add some ioctls of "CUSTOM" type and handle them here.
+ switch (request) {
+ case 0x00008912: { // SIOCGIFCONF
+ struct __sanitizer_ifconf *ifc = (__sanitizer_ifconf *)arg;
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, &ifc->ifc_len, sizeof(ifc->ifc_len));
+ break;
+ }
+ }
return;
}
}
if (desc->type != ioctl_desc::CUSTOM)
return;
- return; // FIXME
+ switch (request) {
+ case 0x00008912: { // SIOCGIFCONF
+ struct __sanitizer_ifconf *ifc = (__sanitizer_ifconf *)arg;
+ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, ifc->ifc_ifcu.ifcu_req, ifc->ifc_len);
+ break;
+ }
+ }
+ return;
}
// ioctl arguments
unsigned struct_arpreq_sz = sizeof(struct arpreq);
- unsigned struct_ifconf_sz = sizeof(struct ifconf);
unsigned struct_ifreq_sz = sizeof(struct ifreq);
unsigned struct_termios_sz = sizeof(struct termios);
unsigned struct_winsize_sz = sizeof(struct winsize);
CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_level);
CHECK_SIZE_AND_OFFSET(cmsghdr, cmsg_type);
+CHECK_TYPE_SIZE(ifconf);
+CHECK_SIZE_AND_OFFSET(ifconf, ifc_len);
+CHECK_SIZE_AND_OFFSET(ifconf, ifc_ifcu);
+
#endif // SANITIZER_LINUX || SANITIZER_MAC
+
};
// ioctl arguments
+ struct __sanitizer_ifconf {
+ int ifc_len;
+ union {
+ void *ifcu_req;
+ } ifc_ifcu;
+ };
+
extern unsigned struct_arpreq_sz;
- extern unsigned struct_ifconf_sz;
extern unsigned struct_ifreq_sz;
extern unsigned struct_termios_sz;
extern unsigned struct_winsize_sz;