Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 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 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 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 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 13 | |
| 14 | #include <assert.h> |
| 15 | #include <sys/wait.h> |
| 16 | #include <unistd.h> |
| 17 | |
| 18 | int 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 Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 30 | #elif defined(WAIT3_RUSAGE) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 31 | struct rusage *ru = (struct rusage*)(x + argc * 3); |
| 32 | int good_status; |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 33 | res = wait3(&good_status, WNOHANG, ru); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 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 | } |