Skip to content

Commit 88e6cba

Browse files
committed
C++: Include Assignments in exprMayThrow and accept test changes.
1 parent 80d41d9 commit 88e6cba

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

cpp/ql/src/experimental/Security/CWE/CWE-570/IncorrectAllocationErrorHandling.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ predicate exprMayThrow(Expr e) {
127127
convertedExprMayThrow([binOp.getLeftOperand(), binOp.getRightOperand()])
128128
)
129129
or
130+
exists(Assignment assign | assign = e |
131+
convertedExprMayThrow([assign.getLValue(), assign.getRValue()])
132+
)
133+
or
130134
exists(CommaExpr comma | comma = e |
131135
convertedExprMayThrow([comma.getLeftOperand(), comma.getRightOperand()])
132136
)

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-570/semmle/tests/IncorrectAllocationErrorHandling.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@
1616
| test.cpp:151:9:151:24 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:152:15:152:18 | { ... } | This catch block |
1717
| test.cpp:199:15:199:35 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:201:16:201:19 | { ... } | This catch block |
1818
| test.cpp:212:14:212:34 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:213:34:213:36 | { ... } | This catch block |
19-
| test.cpp:219:9:219:15 | new | This allocation cannot throw. $@ is unnecessary. | test.cpp:220:34:220:36 | { ... } | This catch block |

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-570/semmle/tests/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,6 @@ void bad_new_catch_baseclass_of_bad_alloc() {
216216
void good_new_catch_exception_in_assignment() {
217217
int* p;
218218
try {
219-
p = new int; // GOOD [FALSE POSITIVE]
219+
p = new int; // GOOD
220220
} catch(const std::bad_alloc&) { }
221221
}

0 commit comments

Comments
 (0)