xref: /minix3/external/bsd/llvm/dist/clang/test/Analysis/chroot.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -analyze -analyzer-checker=alpha.unix.Chroot -analyzer-store region -verify %s
2*f4a2713aSLionel Sambuc 
3*f4a2713aSLionel Sambuc extern int chroot(const char* path);
4*f4a2713aSLionel Sambuc extern int chdir(const char* path);
5*f4a2713aSLionel Sambuc 
foo(void)6*f4a2713aSLionel Sambuc void foo(void) {
7*f4a2713aSLionel Sambuc }
8*f4a2713aSLionel Sambuc 
f1(void)9*f4a2713aSLionel Sambuc void f1(void) {
10*f4a2713aSLionel Sambuc   chroot("/usr/local"); // root changed.
11*f4a2713aSLionel Sambuc   foo(); // expected-warning {{No call of chdir("/") immediately after chroot}}
12*f4a2713aSLionel Sambuc }
13*f4a2713aSLionel Sambuc 
f2(void)14*f4a2713aSLionel Sambuc void f2(void) {
15*f4a2713aSLionel Sambuc   chroot("/usr/local"); // root changed.
16*f4a2713aSLionel Sambuc   chdir("/"); // enter the jail.
17*f4a2713aSLionel Sambuc   foo(); // no-warning
18*f4a2713aSLionel Sambuc }
19*f4a2713aSLionel Sambuc 
f3(void)20*f4a2713aSLionel Sambuc void f3(void) {
21*f4a2713aSLionel Sambuc   chroot("/usr/local"); // root changed.
22*f4a2713aSLionel Sambuc   chdir("../"); // change working directory, still out of jail.
23*f4a2713aSLionel Sambuc   foo(); // expected-warning {{No call of chdir("/") immediately after chroot}}
24*f4a2713aSLionel Sambuc }
25