• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include <assert.h>
9 #include <sys/wait.h>
10 #include <unistd.h>
11 
main(int argc,char ** argv)12 int main(int argc, char **argv) {
13   pid_t pid = fork();
14   if (pid) { // parent
15     int x[3];
16     int *status = x + argc * 3;
17     int res;
18 #if defined(WAIT)
19     res = wait(status);
20 #elif defined(WAITPID)
21     res = waitpid(pid, status, WNOHANG);
22 #endif
23     // CHECK: stack-buffer-overflow
24     // CHECK: {{WRITE of size .* at 0x.* thread T0}}
25     // CHECK: {{in .*wait}}
26     // CHECK: {{in main .*wait.cc:}}
27     // CHECK: is located in stack of thread T0 at offset
28     // CHECK: {{in main}}
29     return res == -1 ? 1 : 0;
30   }
31   // child
32   return 0;
33 }
34