1 // RUN: %clangxx_asan -DWAIT -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s 2 // RUN: %clangxx_asan -DWAIT -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s 3 4 // RUN: %clangxx_asan -DWAITPID -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s 5 // RUN: %clangxx_asan -DWAITPID -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s 6 7 // UNSUPPORTED: darwin 8 9 #include <assert.h> 10 #include <sys/wait.h> 11 #include <unistd.h> 12 13 int main(int argc, char **argv) { 14 pid_t pid = fork(); 15 if (pid) { // parent 16 int x[3]; 17 int *status = x + argc * 3; 18 int res; 19 #if defined(WAIT) 20 res = wait(status); 21 #elif defined(WAITPID) 22 res = waitpid(pid, status, WNOHANG); 23 #endif 24 // CHECK: stack-buffer-overflow 25 // CHECK: {{WRITE of size .* at 0x.* thread T0}} 26 // CHECK: {{in .*wait}} 27 // CHECK: {{in main .*wait.cpp:}} 28 // CHECK: is located in stack of thread T0 at offset 29 // CHECK: {{in main}} 30 return res == -1 ? 1 : 0; 31 } 32 // child 33 return 0; 34 } 35