Skip to content

Commit 4879104

Browse files
committed
C++: Add more dataflow cases to replace the loss.
1 parent b0ad927 commit 4879104

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

cpp/ql/src/Security/CWE/CWE-191/UnsignedDifferenceExpressionComparedZero.ql

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ predicate isGuarded(SubExpr sub, Expr left, Expr right) {
3434
* Holds if `e` is known or suspected to be less than or equal to
3535
* `sub.getLeftOperand()`.
3636
*/
37-
predicate exprIsSubLeftOrLess(SubExpr sub, Expr e) {
37+
predicate exprIsSubLeftOrLess(SubExpr sub, Element e) {
3838
e = sub.getLeftOperand()
3939
or
4040
exists(Expr other |
@@ -46,6 +46,24 @@ predicate exprIsSubLeftOrLess(SubExpr sub, Expr e) {
4646
)
4747
)
4848
or
49+
exists(Element other |
50+
// dataflow (via parameter)
51+
exprIsSubLeftOrLess(sub, other) and
52+
(
53+
DataFlow::localFlowStep(DataFlow::parameterNode(e), DataFlow::exprNode(other)) or
54+
DataFlow::localFlowStep(DataFlow::parameterNode(other), DataFlow::exprNode(e))
55+
)
56+
)
57+
or
58+
exists(Element other |
59+
// dataflow (via uninitialized)
60+
exprIsSubLeftOrLess(sub, other) and
61+
(
62+
DataFlow::localFlowStep(DataFlow::uninitializedNode(e), DataFlow::exprNode(other)) or
63+
DataFlow::localFlowStep(DataFlow::uninitializedNode(other), DataFlow::exprNode(e))
64+
)
65+
)
66+
or
4967
exists(Expr other |
5068
// guard constraining `sub`
5169
exprIsSubLeftOrLess(sub, other) and

cpp/ql/test/query-tests/Security/CWE/CWE-191/UnsignedDifferenceExpressionComparedZero/UnsignedDifferenceExpressionComparedZero.expected

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
| test.cpp:6:5:6:13 | ... > ... | Unsigned subtraction can never be negative. |
22
| test.cpp:10:8:10:24 | ... > ... | Unsigned subtraction can never be negative. |
3-
| test.cpp:22:12:22:20 | ... > ... | Unsigned subtraction can never be negative. |
4-
| test.cpp:32:12:32:20 | ... > ... | Unsigned subtraction can never be negative. |
53
| test.cpp:62:5:62:13 | ... > ... | Unsigned subtraction can never be negative. |
64
| test.cpp:75:8:75:16 | ... > ... | Unsigned subtraction can never be negative. |
75
| test.cpp:101:6:101:14 | ... > ... | Unsigned subtraction can never be negative. |
@@ -11,8 +9,6 @@
119
| test.cpp:152:7:152:15 | ... > ... | Unsigned subtraction can never be negative. |
1210
| test.cpp:182:6:182:14 | ... > ... | Unsigned subtraction can never be negative. |
1311
| test.cpp:208:6:208:14 | ... > ... | Unsigned subtraction can never be negative. |
14-
| test.cpp:219:7:219:15 | ... > ... | Unsigned subtraction can never be negative. |
15-
| test.cpp:226:8:226:16 | ... > ... | Unsigned subtraction can never be negative. |
1612
| test.cpp:252:10:252:18 | ... > ... | Unsigned subtraction can never be negative. |
1713
| test.cpp:266:10:266:24 | ... > ... | Unsigned subtraction can never be negative. |
1814
| test.cpp:276:11:276:19 | ... > ... | Unsigned subtraction can never be negative. |

0 commit comments

Comments
 (0)