1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,security.insecureAPI.vfork,unix.Vfork -verify %s
2 // RUN: %clang_analyze_cc1 -analyzer-checker=core,security.insecureAPI.vfork,unix.Vfork -verify -x c++ %s
4 #include "Inputs/system-header-simulator.h"
8 // Ensure that child process is properly checked.
10 pid_t pid
= vfork(); // expected-warning{{Call to function 'vfork' is insecure}}
16 // Ensure that modifying pid is ok.
17 pid
= 1; // no-warning
18 // Ensure that calling allowlisted routines is ok.
21 execl("", "", 0); // no-warning
24 execle("", "", 0); // no-warning
27 execlp("", "", 0); // no-warning
30 execv("", NULL
); // no-warning
33 execve("", NULL
, NULL
); // no-warning
36 execvp("", NULL
); // no-warning
39 execvpe("", NULL
, NULL
); // no-warning
42 _exit(1); // no-warning
45 // Ensure that writing variables is prohibited.
46 x
= 0; // expected-warning{{This assignment is prohibited after a successful vfork}}
49 // Ensure that calling functions is prohibited.
50 foo(); // expected-warning{{This function call is prohibited after a successful vfork}}
53 // Ensure that returning from function is prohibited.
54 return 0; // expected-warning{{Return is prohibited after a successful vfork; call _exit() instead}}
60 // Same as previous but without explicit pid variable.
62 pid_t pid
= vfork(); // expected-warning{{Call to function 'vfork' is insecure}}
66 // Ensure that writing pid is ok.
67 pid
= 1; // no-warning
68 // Ensure that calling allowlisted routines is ok.
69 execl("", "", 0); // no-warning
70 _exit(1); // no-warning
73 // Ensure that writing variables is prohibited.
74 x
= 0; // expected-warning{{This assignment is prohibited after a successful vfork}}
77 // Ensure that calling functions is prohibited.
78 foo(); // expected-warning{{This function call is prohibited after a successful vfork}}
81 // Ensure that returning from function is prohibited.
82 return 0; // expected-warning{{Return is prohibited after a successful vfork; call _exit() instead}}
88 // Ensure that parent process isn't restricted.
90 if (vfork() == 0) // expected-warning{{Call to function 'vfork' is insecure}}
97 // Unbound pids are special so test them separately.
101 vfork(); // expected-warning{{Call to function 'vfork' is insecure}}
102 x
= 0; // expected-warning{{This assignment is prohibited after a successful vfork}}
108 switch (vfork()) { // expected-warning{{Call to function 'vfork' is insecure}}
110 args
[0] = 0; // expected-warning{{This assignment is prohibited after a successful vfork}}
119 if ((pid
= vfork()) == 0) // expected-warning{{Call to function 'vfork' is insecure}}
120 while(1); // no-warning
129 // See "libxtables: move some code to avoid cautions in vfork man page"
130 // (http://lists.netfilter.org/pipermail/netfilter-buglog/2014-October/003280.html).
131 if (vfork() == 0) { // expected-warning{{Call to function 'vfork' is insecure}}
132 execl("prog", "arg1", 0); // no-warning
133 exit(1); // expected-warning{{This function call is prohibited after a successful vfork}}