xref: /aosp_15_r20/external/compiler-rt/test/asan/TestCases/Posix/waitid.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
2*7c3d14c8STreehugger Robot // RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
3*7c3d14c8STreehugger Robot 
4*7c3d14c8STreehugger Robot #include <assert.h>
5*7c3d14c8STreehugger Robot #include <sys/wait.h>
6*7c3d14c8STreehugger Robot #include <unistd.h>
7*7c3d14c8STreehugger Robot #include <signal.h>
8*7c3d14c8STreehugger Robot 
main(int argc,char ** argv)9*7c3d14c8STreehugger Robot int main(int argc, char **argv) {
10*7c3d14c8STreehugger Robot   pid_t pid = fork();
11*7c3d14c8STreehugger Robot   if (pid) { // parent
12*7c3d14c8STreehugger Robot     int x[3];
13*7c3d14c8STreehugger Robot     int *status = x + argc * 3;
14*7c3d14c8STreehugger Robot     int res;
15*7c3d14c8STreehugger Robot 
16*7c3d14c8STreehugger Robot     siginfo_t *si = (siginfo_t*)(x + argc * 3);
17*7c3d14c8STreehugger Robot     res = waitid(P_ALL, 0, si, WEXITED | WNOHANG);
18*7c3d14c8STreehugger Robot     // CHECK: stack-buffer-overflow
19*7c3d14c8STreehugger Robot     // CHECK: {{WRITE of size .* at 0x.* thread T0}}
20*7c3d14c8STreehugger Robot     // CHECK: {{in .*waitid}}
21*7c3d14c8STreehugger Robot     // CHECK: {{in main .*waitid.cc:}}
22*7c3d14c8STreehugger Robot     // CHECK: is located in stack of thread T0 at offset
23*7c3d14c8STreehugger Robot     // CHECK: {{in main}}
24*7c3d14c8STreehugger Robot     return res != -1;
25*7c3d14c8STreehugger Robot   }
26*7c3d14c8STreehugger Robot   // child
27*7c3d14c8STreehugger Robot   return 0;
28*7c3d14c8STreehugger Robot }
29