Skip to content

Commit 7d8886e

Browse files
committed
CPP: Fix over-enthusiastic dataflow in allocExprOrIndirect.
1 parent ea7e892 commit 7d8886e

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

cpp/ql/src/Critical/NewDelete.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ predicate allocExprOrIndirect(Expr alloc, string kind) {
4646
alloc.(FunctionCall).getTarget() = rtn.getEnclosingFunction() and
4747
(
4848
allocExprOrIndirect(rtn.getExpr(), kind) or
49-
allocReaches0(rtn.getExpr(), _, kind)
49+
exists(SsaDefinition def, LocalScopeVariable v |
50+
// alloc via SSA
51+
allocExprOrIndirect(def.getAnUltimateDefiningValue(v), kind) and
52+
rtn.getExpr() = def.getAUse(v)
53+
)
5054
)
5155
)
5256
}

cpp/ql/test/query-tests/Critical/NewFree/NewFreeMismatch.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
| test.cpp:91:3:91:11 | delete | There is a malloc/delete mismatch between this delete and the corresponding $@. | test.cpp:88:28:88:36 | call to my_malloc | malloc |
77
| test.cpp:99:3:99:11 | call to my_delete | There is a malloc/delete mismatch between this delete and the corresponding $@. | test.cpp:96:28:96:33 | call to malloc | malloc |
88
| test.cpp:138:2:138:9 | delete | There is a malloc/delete mismatch between this delete and the corresponding $@. | test.cpp:135:12:135:22 | call to my_malloc_2 | malloc |
9-
| test.cpp:155:2:155:9 | delete | There is a malloc/delete mismatch between this delete and the corresponding $@. | test.cpp:152:12:152:22 | call to my_malloc_3 | malloc |
109
| test.cpp:232:2:232:9 | delete | There is a malloc/delete mismatch between this delete and the corresponding $@. | test.cpp:226:7:226:12 | call to malloc | malloc |
1110
| test.cpp:233:2:233:12 | delete[] | There is a malloc/delete mismatch between this delete[] and the corresponding $@. | test.cpp:226:7:226:12 | call to malloc | malloc |
1211
| test.cpp:235:2:235:5 | call to free | There is a new/free mismatch between this free and the corresponding $@. | test.cpp:227:7:227:13 | new | new |
1312
| test.cpp:239:2:239:5 | call to free | There is a new/free mismatch between this free and the corresponding $@. | test.cpp:228:7:228:17 | new[] | new[] |
1413
| test.cpp:272:3:272:6 | call to free | There is a new/free mismatch between this free and the corresponding $@. | test.cpp:265:7:265:13 | new | new |
15-
| test.cpp:425:2:425:31 | delete | There is a malloc/delete mismatch between this delete and the corresponding $@. | test.cpp:425:20:425:29 | call to getPointer | malloc |

cpp/ql/test/query-tests/Critical/NewFree/test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void test3()
152152
void *b = my_malloc_3(10);
153153

154154
free(a); // GOOD
155-
delete b; // BAD: malloc -> delete
155+
delete b; // BAD: malloc -> delete [NOT DETECTED]
156156
}
157157

158158
void test4(bool do_array_delete)
@@ -422,5 +422,5 @@ void test13()
422422
MyPointer13 myPointer2(myBuffer);
423423
MyPointer13 myPointer3(new char[100]);
424424

425-
delete myPointer2.getPointer(); // GOOD [FALSE POSITIVE]
425+
delete myPointer2.getPointer(); // GOOD
426426
}

0 commit comments

Comments
 (0)