29 lines · cpp
1// RUN: %clangxx_asan -O0 -g %s -o %t && %env_asan_opts=handle_ioctl=1 not %run %t 2>&1 | FileCheck %s2// RUN: %clangxx_asan -O3 -g %s -o %t && %env_asan_opts=handle_ioctl=1 not %run %t 2>&1 | FileCheck %s3 4// RUN: %clangxx_asan -O0 -g %s -o %t && %run %t5// RUN: %clangxx_asan -O3 -g %s -o %t && %run %t6 7#include <assert.h>8#include <stdlib.h>9#include <sys/ioctl.h>10#include <sys/socket.h>11#include <unistd.h>12 13#if defined(__sun__) && defined(__svr4__)14#include <sys/filio.h>15#endif16 17int main(int argc, char **argv) {18 int fd = socket(AF_UNIX, SOCK_DGRAM, 0);19 20 int nonblock;21 int res = ioctl(fd, FIONBIO, &nonblock + 1);22 // CHECK: AddressSanitizer: stack-buffer-overflow23 // CHECK: READ of size 4 at24 // CHECK: {{#.* in main .*ioctl.cpp:}}[[@LINE-3]]25 assert(res == 0);26 close(fd);27 return 0;28}29