blob: 99d0212acfabc1d0f85692604b40bfe34e5bba36 [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001// 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
Stephen Hines2d1fdb22014-05-28 23:58:16 -070010// 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
Stephen Hines2d1fdb22014-05-28 23:58:16 -070013
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);
Stephen Hines6d186232014-11-26 17:56:19 -080030#elif defined(WAIT3_RUSAGE)
Stephen Hines2d1fdb22014-05-28 23:58:16 -070031 struct rusage *ru = (struct rusage*)(x + argc * 3);
32 int good_status;
Stephen Hines2d1fdb22014-05-28 23:58:16 -070033 res = wait3(&good_status, WNOHANG, ru);
Stephen Hines2d1fdb22014-05-28 23:58:16 -070034#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}