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

source code of compiler-rt/test/asan/TestCases/Posix/readv.cpp