Skip to content

Commit 7f0a7bb

Browse files
authored
Update IncorrectPrivilegeAssignment.ql
1 parent 7832e85 commit 7f0a7bb

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ import cpp
1919
import semmle.code.cpp.exprs.BitwiseOperation
2020
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
2121

22+
/**
23+
* An expression that is either a `BinaryArithmeticOperation` or the result of one or more `BinaryBitwiseOperation`s on a `BinaryArithmeticOperation`. For example `1 | (2 + 3)`.
24+
*/
25+
class ContainsArithmetic extends Expr {
26+
ContainsArithmetic() {
27+
this instanceof BinaryArithmeticOperation
28+
or
29+
// recursive search into `Operation`s
30+
this.(BinaryBitwiseOperation).getAnOperand() instanceof ContainsArithmetic
31+
}
32+
}
33+
2234
/** Holds for a function `f` that has an argument at index `apos` used to set file permissions. */
2335
predicate numberArgumentModFunctions(Function f, int apos) {
2436
f.hasGlobalOrStdName("umask") and apos = 0
@@ -63,15 +75,9 @@ where
6375
msg = "not use equal argument in umask and " + fctmp.getTarget().getName() + " functions"
6476
)
6577
or
66-
exists(Expr exptmp, int i |
78+
exists(ContainsArithmetic exptmp, int i |
6779
numberArgumentModFunctions(fc.getTarget(), i) and
6880
globalValueNumber(exptmp) = globalValueNumber(fc.getArgument(i)) and
69-
exptmp.getAChild*() instanceof BinaryArithmeticOperation and
70-
not exptmp.getAChild*() instanceof FunctionCall and
71-
not exists(SizeofOperator so | exptmp.getAChild*() = so) and
72-
not exists(ArrayExpr aetmp | aetmp.getArrayOffset() = exptmp.getAChild*()) and
73-
not exptmp.getAChild*() instanceof BinaryBitwiseOperation and
74-
not exptmp.isConstant() and
7581
msg = "Using arithmetic to compute the mask may not be safe."
7682
)
7783
select fc, msg

0 commit comments

Comments
 (0)