Skip to content

Commit 4bab256

Browse files
committed
Clarify some docs
1 parent b2edb86 commit 4bab256

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

clang/docs/analyzer/checkers.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,19 +1757,25 @@ unix.Chroot (C)
17571757
Check improper use of chroot described by SEI Cert C recommendation `POS05-C.
17581758
Limit access to files by creating a jail
17591759
<https://wiki.sei.cmu.edu/confluence/display/c/POS05-C.+Limit+access+to+files+by+creating+a+jail>`_.
1760-
The checker finds usage patterns where chdir() is not called immediately
1761-
after a call to chroot().
1760+
The checker finds usage patterns where ``chdir("/")`` is not called immediately
1761+
after a call to ``chroot(path)``.
17621762
17631763
.. code-block:: c
17641764
17651765
void f();
17661766
1767-
void test() {
1767+
void test_bad() {
17681768
chroot("/usr/local");
17691769
f(); // warn: no call of chdir("/") immediately after chroot
17701770
}
17711771
1772-
void test() {
1772+
void test_bad_path() {
1773+
chroot("/usr/local");
1774+
chdir("/usr"); // warn: no call of chdir("/") immediately after chroot
1775+
f();
1776+
}
1777+
1778+
void test_good() {
17731779
chroot("/usr/local");
17741780
chdir("/"); // no warning
17751781
f();

clang/test/Analysis/chroot.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,11 @@ void f7(void) {
5858
// expected-note@-2 {{No call of chdir("/") immediately after chroot}}
5959
}
6060
}
61+
62+
void f8() {
63+
chroot("/usr/local"); // expected-note {{chroot called here}}
64+
chdir("/usr"); // This chdir was ineffective because it's not exactly `chdir("/")`.
65+
foo();
66+
// expected-warning@-1 {{No call of chdir("/") immediately after chroot}}
67+
// expected-note@-2 {{No call of chdir("/") immediately after chroot}}
68+
}

0 commit comments

Comments
 (0)