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// RUN: %clangxx_asan -DWAIT3 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s 8// RUN: %clangxx_asan -DWAIT3 -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s 9 10// RUN: %clangxx_asan -DWAIT3_RUSAGE -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s 11// RUN: %clangxx_asan -DWAIT3_RUSAGE -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s 12 13 14#include <assert.h> 15#include <sys/wait.h> 16#include <unistd.h> 17 18int main(int argc, char **argv) { 19 pid_t pid = fork(); 20 if (pid) { // parent 21 int x[3]; 22 int *status = x + argc * 3; 23 int res; 24#if defined(WAIT) 25 res = wait(status); 26#elif defined(WAITPID) 27 res = waitpid(pid, status, WNOHANG); 28#elif defined(WAIT3) 29 res = wait3(status, WNOHANG, NULL); 30#elif defined(WAIT3_RUSAGE) 31 struct rusage *ru = (struct rusage*)(x + argc * 3); 32 int good_status; 33 res = wait3(&good_status, WNOHANG, ru); 34#endif 35 // CHECK: stack-buffer-overflow 36 // CHECK: {{WRITE of size .* at 0x.* thread T0}} 37 // CHECK: {{in .*wait}} 38 // CHECK: {{in main .*wait.cc:}} 39 // CHECK: is located in stack of thread T0 at offset 40 // CHECK: {{in main}} 41 return res == -1 ? 1 : 0; 42 } 43 // child 44 return 0; 45} 46