xref: /aosp_15_r20/external/compiler-rt/test/asan/TestCases/Posix/ioctl.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O0 -g %s -o %t && %env_asan_opts=handle_ioctl=1 not %run %t 2>&1 | FileCheck %s
2*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O3 -g %s -o %t && %env_asan_opts=handle_ioctl=1 not %run %t 2>&1 | FileCheck %s
3*7c3d14c8STreehugger Robot 
4*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O0 -g %s -o %t && %run %t
5*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O3 -g %s -o %t && %run %t
6*7c3d14c8STreehugger Robot 
7*7c3d14c8STreehugger Robot #include <assert.h>
8*7c3d14c8STreehugger Robot #include <stdlib.h>
9*7c3d14c8STreehugger Robot #include <sys/ioctl.h>
10*7c3d14c8STreehugger Robot #include <sys/socket.h>
11*7c3d14c8STreehugger Robot #include <unistd.h>
12*7c3d14c8STreehugger Robot 
main(int argc,char ** argv)13*7c3d14c8STreehugger Robot int main(int argc, char **argv) {
14*7c3d14c8STreehugger Robot   int fd = socket(AF_INET, SOCK_DGRAM, 0);
15*7c3d14c8STreehugger Robot 
16*7c3d14c8STreehugger Robot   int nonblock;
17*7c3d14c8STreehugger Robot   int res = ioctl(fd, FIONBIO, &nonblock + 1);
18*7c3d14c8STreehugger Robot   // CHECK: AddressSanitizer: stack-buffer-overflow
19*7c3d14c8STreehugger Robot   // CHECK: READ of size 4 at
20*7c3d14c8STreehugger Robot   // CHECK: {{#.* in main .*ioctl.cc:}}[[@LINE-3]]
21*7c3d14c8STreehugger Robot   assert(res == 0);
22*7c3d14c8STreehugger Robot   close(fd);
23*7c3d14c8STreehugger Robot   return 0;
24*7c3d14c8STreehugger Robot }
25