blob: 6cf9fa8e3cd3beb8928ff0cd81db76615df9c547 [file] [log] [blame]
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08001// RUN: %clangxx_asan -O0 -g %s -o %t && %env_asan_opts=handle_ioctl=1 not %run %t 2>&1 | FileCheck %s
2// RUN: %clangxx_asan -O3 -g %s -o %t && %env_asan_opts=handle_ioctl=1 not %run %t 2>&1 | FileCheck %s
Stephen Hines2d1fdb22014-05-28 23:58:16 -07003
4// RUN: %clangxx_asan -O0 -g %s -o %t && %run %t
5// RUN: %clangxx_asan -O3 -g %s -o %t && %run %t
6
7#include <assert.h>
8#include <stdlib.h>
9#include <sys/ioctl.h>
10#include <sys/socket.h>
11#include <unistd.h>
12
13int main(int argc, char **argv) {
14 int fd = socket(AF_INET, SOCK_DGRAM, 0);
15
16 int nonblock;
17 int res = ioctl(fd, FIONBIO, &nonblock + 1);
18 // CHECK: AddressSanitizer: stack-buffer-overflow
19 // CHECK: READ of size 4 at
20 // CHECK: {{#.* in main .*ioctl.cc:}}[[@LINE-3]]
21 assert(res == 0);
22 close(fd);
23 return 0;
24}