Skip to content

Commit a1755b0

Browse files
authored
Update OperatorPrecedenceLogicErrorWhenUseBitwiseOrLogicalOperations.ql
1 parent e5c30c2 commit a1755b0

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

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

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ predicate isLogicalOrandBitwise(Expr exptmp) {
2929
(
3030
exptmp.(LogicalOrExpr).getRightOperand().(BinaryBitwiseOperation).getLeftOperand().getType()
3131
instanceof BoolType and
32-
/**
33-
* The essence of these lines is to improve the quality of detection by eliminating the situation
34-
* of processing a logical type by bit operations. In fact, the predicate looks for a situation
35-
* when the left operand of a bit operation has a boolean type, which already suggests that the priority is not correct.
36-
* But if the right-hand operand is 0 or 1, then there is a possibility that the author intended so.
37-
*/
32+
// The essence of these lines is to improve the quality of detection by eliminating the situation
33+
// of processing a logical type by bit operations. In fact, the predicate looks for a situation
34+
// when the left operand of a bit operation has a boolean type, which already suggests that the priority is not correct.
35+
// But if the right-hand operand is 0 or 1, then there is a possibility that the author intended so.
3836
not exptmp
3937
.(LogicalOrExpr)
4038
.getRightOperand()
@@ -54,12 +52,10 @@ predicate isLogicalOrandBitwise(Expr exptmp) {
5452
(
5553
exptmp.(LogicalAndExpr).getRightOperand().(BinaryBitwiseOperation).getLeftOperand().getType()
5654
instanceof BoolType and
57-
/**
58-
* Looking for a situation in which the right-hand operand of a bit operation is not limited to 0 or 1.
59-
* In this case, the logical operation will be performed with the result of a binary operation that is not a Boolean type.
60-
* In my opinion this indicates a priority error. after all, it will be quite difficult for a developer
61-
* to evaluate the conversion of the results of a bit operation to a boolean type.
62-
*/
55+
// Looking for a situation in which the right-hand operand of a bit operation is not limited to 0 or 1.
56+
// In this case, the logical operation will be performed with the result of a binary operation that is not a Boolean type.
57+
// In my opinion this indicates a priority error. after all, it will be quite difficult for a developer
58+
// to evaluate the conversion of the results of a bit operation to a boolean type.
6359
not exptmp
6460
.(LogicalAndExpr)
6561
.getRightOperand()
@@ -177,22 +173,18 @@ where
177173
isLogicalOrandBitwise(exp) and
178174
msg = "Binary operations have higher priority."
179175
or
180-
/**
181-
* Looking for a situation where the equality of the sizes of the first operands
182-
* might indicate that the developer planned to perform an operation between them.
183-
* However, the absence of parentheses means that the rightmost operation will be performed initially.
184-
*/
176+
// Looking for a situation where the equality of the sizes of the first operands
177+
// might indicate that the developer planned to perform an operation between them.
178+
// However, the absence of parentheses means that the rightmost operation will be performed initially.
185179
isBitwiseandBitwise(exp) and
186180
isDifferentSize(exp.(BinaryBitwiseOperation).getLeftOperand(),
187181
exp.(BinaryBitwiseOperation).getRightOperand().(BinaryBitwiseOperation).getLeftOperand(),
188182
exp.(BinaryBitwiseOperation).getRightOperand().(BinaryBitwiseOperation).getRightOperand()) and
189183
msg = "Expression ranges do not match operation precedence."
190184
or
191-
/**
192-
* Looking for a out those expressions that, as a result of identifying the priority with parentheses,
193-
* will give different values. As a consequence, this piece of code was supposed to find errors associated
194-
* with possible outcomes of operations.
195-
*/
185+
// Looking for a out those expressions that, as a result of identifying the priority with parentheses,
186+
// will give different values. As a consequence, this piece of code was supposed to find errors associated
187+
// with possible outcomes of operations.
196188
isBitwiseandBitwise(exp) and
197189
isDifferentResults(exp.(BinaryBitwiseOperation).getLeftOperand(),
198190
exp.(BinaryBitwiseOperation).getRightOperand().(BinaryBitwiseOperation).getLeftOperand(),

0 commit comments

Comments
 (0)