xref: /aosp_15_r20/external/compiler-rt/test/asan/TestCases/Posix/readv.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O0 %s -o %t && %run %t
2*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O0 %s -DPOSITIVE -o %t && not %run %t 2>&1 | FileCheck %s
3*7c3d14c8STreehugger Robot 
4*7c3d14c8STreehugger Robot // Test the readv() interceptor.
5*7c3d14c8STreehugger Robot 
6*7c3d14c8STreehugger Robot #include <assert.h>
7*7c3d14c8STreehugger Robot #include <stdio.h>
8*7c3d14c8STreehugger Robot #include <stdlib.h>
9*7c3d14c8STreehugger Robot #include <unistd.h>
10*7c3d14c8STreehugger Robot #include <fcntl.h>
11*7c3d14c8STreehugger Robot #include <sys/uio.h>
12*7c3d14c8STreehugger Robot #include <time.h>
13*7c3d14c8STreehugger Robot 
main()14*7c3d14c8STreehugger Robot int main() {
15*7c3d14c8STreehugger Robot   char buf[2011];
16*7c3d14c8STreehugger Robot   struct iovec iov[2];
17*7c3d14c8STreehugger Robot #ifdef POSITIVE
18*7c3d14c8STreehugger Robot   char * volatile buf_ = buf;
19*7c3d14c8STreehugger Robot   iov[0].iov_base = buf_ - 1;
20*7c3d14c8STreehugger Robot #else
21*7c3d14c8STreehugger Robot   iov[0].iov_base = buf + 1;
22*7c3d14c8STreehugger Robot #endif
23*7c3d14c8STreehugger Robot   iov[0].iov_len = 5;
24*7c3d14c8STreehugger Robot   iov[1].iov_base = buf + 10;
25*7c3d14c8STreehugger Robot   iov[1].iov_len = 2000;
26*7c3d14c8STreehugger Robot   int fd = open("/etc/hosts", O_RDONLY);
27*7c3d14c8STreehugger Robot   assert(fd > 0);
28*7c3d14c8STreehugger Robot   readv(fd, iov, 2);
29*7c3d14c8STreehugger Robot   // CHECK: WRITE of size 5 at
30*7c3d14c8STreehugger Robot   close(fd);
31*7c3d14c8STreehugger Robot   return 0;
32*7c3d14c8STreehugger Robot }
33