summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test/asan/TestCases/ioctl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'compiler-rt/test/asan/TestCases/ioctl.cc')
-rw-r--r--compiler-rt/test/asan/TestCases/ioctl.cc24
1 files changed, 24 insertions, 0 deletions
diff --git a/compiler-rt/test/asan/TestCases/ioctl.cc b/compiler-rt/test/asan/TestCases/ioctl.cc
new file mode 100644
index 00000000000..08ca688d387
--- /dev/null
+++ b/compiler-rt/test/asan/TestCases/ioctl.cc
@@ -0,0 +1,24 @@
+// RUN: %clangxx_asan -O0 -g %s -o %t && ASAN_OPTIONS=handle_ioctl=1 not %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 -g %s -o %t && ASAN_OPTIONS=handle_ioctl=1 not %t 2>&1 | FileCheck %s
+
+// RUN: %clangxx_asan -O0 -g %s -o %t && %t
+// RUN: %clangxx_asan -O3 -g %s -o %t && %t
+
+#include <assert.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+int main(int argc, char **argv) {
+ int fd = socket(AF_INET, SOCK_DGRAM, 0);
+
+ int nonblock;
+ int res = ioctl(fd, FIONBIO, &nonblock + 1);
+ // CHECK: AddressSanitizer: stack-buffer-overflow
+ // CHECK: READ of size 4 at
+ // CHECK: {{#.* in main .*ioctl.cc:}}[[@LINE-3]]
+ assert(res == 0);
+ close(fd);
+ return 0;
+}
OpenPOWER on IntegriCloud