Skip to content

Commit 6e8d56f

Browse files
authored
Update IncorrectPrivilegeAssignment.ql
1 parent 21ab8b0 commit 6e8d56f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-266/IncorrectPrivilegeAssignment.ql

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ predicate numberArgumentModFunctions(Function f, int apos) {
4040
f.hasGlobalOrStdName("chmod") and apos = 1
4141
}
4242

43-
from FunctionCall fc, string msg
43+
from FunctionCall fc, string msg, FunctionCall fcsnd
4444
where
4545
fc.getTarget().hasGlobalOrStdName("umask") and
4646
fc.getArgument(0).getValue() = "0" and
@@ -54,13 +54,14 @@ where
5454
fctmp.getTarget().hasGlobalOrStdName("open")
5555
) and
5656
fctmp.getNumberOfArguments() = 2 and
57-
not fctmp.getArgument(0).getValue() = "/dev/null"
57+
not fctmp.getArgument(0).getValue() = "/dev/null" and
58+
fcsnd = fctmp
5859
) and
5960
not exists(FunctionCall fctmp |
6061
fctmp.getTarget().hasGlobalOrStdName("chmod") or
6162
fctmp.getTarget().hasGlobalOrStdName("fchmod")
6263
) and
63-
msg = "Using umask (0) may not be safe."
64+
msg = "Using umask(0) may not be safe with call $@."
6465
or
6566
fc.getTarget().hasGlobalOrStdName("umask") and
6667
exists(FunctionCall fctmp |
@@ -72,12 +73,14 @@ where
7273
globalValueNumber(fc.getArgument(0)) = globalValueNumber(fctmp.getArgument(1)) and
7374
fc.getArgument(0).getValue() != "0"
7475
) and
75-
msg = "not use equal argument in umask and " + fctmp.getTarget().getName() + " functions"
76+
msg = "Not use equal argument in umask and $@ functions." and
77+
fcsnd = fctmp
7678
)
7779
or
7880
exists(ContainsArithmetic exptmp, int i |
7981
numberArgumentModFunctions(fc.getTarget(), i) and
8082
globalValueNumber(exptmp) = globalValueNumber(fc.getArgument(i)) and
81-
msg = "Using arithmetic to compute the mask may not be safe."
83+
msg = "Using arithmetic to compute the mask in $@ may not be safe." and
84+
fcsnd = fc
8285
)
83-
select fc, msg
86+
select fc, msg, fcsnd, fcsnd.getTarget().getName()

0 commit comments

Comments
 (0)