Skip to content

Commit c85edb6

Browse files
committed
C++: Use [, ] in the query.
1 parent 7684796 commit c85edb6

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

cpp/ql/src/Security/CWE/CWE-367/TOCTOUFilesystemRace.ql

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,14 @@ import semmle.code.cpp.controlflow.Guards
2626
*/
2727
FunctionCall filenameOperation(Expr path) {
2828
exists(string name | name = result.getTarget().getName() |
29-
(
30-
name = "remove" or
31-
name = "unlink" or
32-
name = "rmdir" or
33-
name = "rename" or
34-
name = "chmod" or
35-
name = "chown" or
36-
name = "fopen" or
37-
name = "open" or
38-
name = "freopen" or
39-
name = "_open" or
40-
name = "_wopen" or
41-
name = "_wfopen"
42-
) and
29+
name =
30+
[
31+
"remove", "unlink", "rmdir", "rename", "chmod", "chown", "fopen", "open", "freopen",
32+
"_open", "_wopen", "_wfopen"
33+
] and
4334
result.getArgument(0) = path
4435
or
45-
(
46-
name = "fopen_s" or
47-
name = "wfopen_s"
48-
) and
36+
name = ["fopen_s", "wfopen_s"] and
4937
result.getArgument(1) = path
5038
)
5139
}
@@ -56,11 +44,7 @@ FunctionCall filenameOperation(Expr path) {
5644
*/
5745
FunctionCall accessCheck(Expr path) {
5846
exists(string name | name = result.getTarget().getName() |
59-
name = "access" or
60-
name = "_access" or
61-
name = "_waccess" or
62-
name = "_access_s" or
63-
name = "_waccess_s"
47+
name = ["access", "_access", "_waccess", "_access_s", "_waccess_s"]
6448
) and
6549
path = result.getArgument(0)
6650
}
@@ -72,9 +56,7 @@ FunctionCall accessCheck(Expr path) {
7256
*/
7357
FunctionCall stat(Expr path, Expr buf) {
7458
exists(string name | name = result.getTarget().getName() |
75-
name = "stat" or
76-
name = "lstat" or
77-
name = "fstat" or
59+
name = ["stat", "lstat", "fstat"] or
7860
name.matches("\\_stat%") or
7961
name.matches("\\_wstat%")
8062
) and

0 commit comments

Comments
 (0)