Skip to content

Commit 3f215d0

Browse files
authored
Update OperatorPrecedenceLogicErrorWhenUseBoolType.ql
1 parent 093c63e commit 3f215d0

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-783/OperatorPrecedenceLogicErrorWhenUseBoolType.ql

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
*/
1414

1515
import cpp
16-
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
16+
import semmle.code.cpp.valuenumbering.HashCons
1717

1818
/** Holds if `exp` increments a boolean value. */
19-
predicate incrementBoolType(Expr exp) {
20-
exp.(IncrementOperation).getOperand().getType() instanceof BoolType
19+
predicate incrementBoolType(IncrementOperation exp) {
20+
exp.getOperand().getType() instanceof BoolType
2121
}
2222

2323
/** Holds if `exp` applies the unary minus operator to a boolean type. */
24-
predicate revertSignBoolType(Expr exp) {
25-
exp.(AssignExpr).getRValue().(UnaryMinusExpr).getAnOperand().getType() instanceof BoolType and
26-
exp.(AssignExpr).getLValue().getType() instanceof BoolType
24+
predicate revertSignBoolType(UnaryMinusExpr exp) {
25+
exp.getAnOperand().getType() instanceof BoolType and
26+
exp.getFullyConverted().getType() instanceof BoolType
2727
}
2828

2929
/** Holds, if this is an expression, uses comparison and assignment outside of execution precedence. */
@@ -33,6 +33,12 @@ predicate assignBoolType(Expr exp) {
3333
exp.isCondition() and
3434
not co.isParenthesised() and
3535
not exp.(AssignExpr).getLValue().getType() instanceof BoolType and
36+
not exists(Expr exbl |
37+
hashCons(exbl.(AssignExpr).getLValue()) = hashCons(exp.(AssignExpr).getLValue()) and
38+
not exbl.isCondition() and
39+
exbl.(AssignExpr).getRValue().getType() instanceof BoolType and
40+
exbl.(AssignExpr).getLValue().getType() = exp.(AssignExpr).getLValue().getType()
41+
) and
3642
co.getLeftOperand() instanceof FunctionCall and
3743
not co.getRightOperand().getType() instanceof BoolType and
3844
not co.getRightOperand().getValue() = "0" and

0 commit comments

Comments
 (0)