Skip to content

Commit 289d587

Browse files
authored
Update InsecureTemporaryFile.ql
1 parent 55fe010 commit 289d587

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-377/InsecureTemporaryFile.ql

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,16 @@ where
4646
fc.getTarget().hasGlobalOrStdName("tmpnam_r")
4747
) and
4848
not exists(FunctionCall fctmp |
49-
fctmp.getTarget().hasGlobalOrStdName("mktemp") or
50-
fctmp.getTarget().hasGlobalOrStdName("mkstemp") or
51-
fctmp.getTarget().hasGlobalOrStdName("mkstemps") or
52-
fctmp.getTarget().hasGlobalOrStdName("mkdtemp")
49+
(
50+
fctmp.getTarget().hasGlobalOrStdName("mktemp") or
51+
fctmp.getTarget().hasGlobalOrStdName("mkstemp") or
52+
fctmp.getTarget().hasGlobalOrStdName("mkstemps") or
53+
fctmp.getTarget().hasGlobalOrStdName("mkdtemp")
54+
) and
55+
(
56+
fc.getBasicBlock().getASuccessor*() = fctmp.getBasicBlock() or
57+
fctmp.getBasicBlock().getASuccessor*() = fc.getBasicBlock()
58+
)
5359
) and
5460
msg =
5561
"Finding the name of a file that does not exist does not mean that it will not be exist at the next operation."
@@ -91,9 +97,15 @@ where
9197
)
9298
) and
9399
not exists(FunctionCall fctmp |
94-
fctmp.getTarget().hasGlobalOrStdName("umask") or
95-
fctmp.getTarget().hasGlobalOrStdName("fchmod") or
96-
fctmp.getTarget().hasGlobalOrStdName("chmod")
100+
(
101+
fctmp.getTarget().hasGlobalOrStdName("umask") or
102+
fctmp.getTarget().hasGlobalOrStdName("fchmod") or
103+
fctmp.getTarget().hasGlobalOrStdName("chmod")
104+
) and
105+
(
106+
fc.getBasicBlock().getASuccessor*() = fctmp.getBasicBlock() or
107+
fctmp.getBasicBlock().getASuccessor*() = fc.getBasicBlock()
108+
)
97109
) and
98110
msg =
99111
"Creating a file for writing without evaluating its existence and setting permissions can be unsafe."

0 commit comments

Comments
 (0)