Skip to content

Commit 23a7cd9

Browse files
committed
C++: Fix missing result and accept test changes.
1 parent 416f8d5 commit 23a7cd9

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

cpp/ql/src/Critical/UseAfterFree.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ predicate isUse0(DataFlow::Node n, Expr e) {
3939
or
4040
e = any(ArrayExpr ae).getArrayBase()
4141
or
42+
e = any(Call call).getQualifier()
43+
or
4244
// Assume any function without a body will dereference the pointer
4345
exists(int i, Call call, Function f |
4446
n.asExpr() = call.getArgument(i) and

cpp/ql/test/query-tests/Critical/MemoryFreed/UseAfterFree.expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ edges
99
| test_free.cpp:44:27:44:27 | a | test_free.cpp:45:5:45:5 | a |
1010
| test_free.cpp:69:10:69:10 | a | test_free.cpp:71:9:71:9 | a |
1111
| test_free.cpp:69:10:69:10 | a | test_free.cpp:71:9:71:9 | a |
12+
| test_free.cpp:90:10:90:10 | a | test_free.cpp:91:5:91:5 | a |
13+
| test_free.cpp:90:10:90:10 | a | test_free.cpp:91:5:91:5 | a |
1214
| test_free.cpp:95:10:95:10 | a | test_free.cpp:96:9:96:9 | a |
1315
| test_free.cpp:101:10:101:10 | a | test_free.cpp:102:23:102:23 | a |
1416
| test_free.cpp:152:27:152:27 | a | test_free.cpp:153:5:153:5 | a |
@@ -28,6 +30,9 @@ nodes
2830
| test_free.cpp:69:10:69:10 | a | semmle.label | a |
2931
| test_free.cpp:69:10:69:10 | a | semmle.label | a |
3032
| test_free.cpp:71:9:71:9 | a | semmle.label | a |
33+
| test_free.cpp:90:10:90:10 | a | semmle.label | a |
34+
| test_free.cpp:90:10:90:10 | a | semmle.label | a |
35+
| test_free.cpp:91:5:91:5 | a | semmle.label | a |
3136
| test_free.cpp:95:10:95:10 | a | semmle.label | a |
3237
| test_free.cpp:96:9:96:9 | a | semmle.label | a |
3338
| test_free.cpp:101:10:101:10 | a | semmle.label | a |
@@ -49,6 +54,8 @@ subpaths
4954
| test_free.cpp:45:5:45:5 | a | test_free.cpp:44:27:44:27 | a | test_free.cpp:45:5:45:5 | a | Memory may have been previously freed by $@. | test_free.cpp:44:22:44:25 | call to free | call to free |
5055
| test_free.cpp:71:9:71:9 | a | test_free.cpp:69:10:69:10 | a | test_free.cpp:71:9:71:9 | a | Memory may have been previously freed by $@. | test_free.cpp:69:5:69:8 | call to free | call to free |
5156
| test_free.cpp:71:9:71:9 | a | test_free.cpp:69:10:69:10 | a | test_free.cpp:71:9:71:9 | a | Memory may have been previously freed by $@. | test_free.cpp:69:5:69:8 | call to free | call to free |
57+
| test_free.cpp:91:5:91:5 | a | test_free.cpp:90:10:90:10 | a | test_free.cpp:91:5:91:5 | a | Memory may have been previously freed by $@. | test_free.cpp:90:5:90:8 | call to free | call to free |
58+
| test_free.cpp:91:5:91:5 | a | test_free.cpp:90:10:90:10 | a | test_free.cpp:91:5:91:5 | a | Memory may have been previously freed by $@. | test_free.cpp:90:5:90:8 | call to free | call to free |
5259
| test_free.cpp:96:9:96:9 | a | test_free.cpp:95:10:95:10 | a | test_free.cpp:96:9:96:9 | a | Memory may have been previously freed by $@. | test_free.cpp:95:5:95:8 | call to free | call to free |
5360
| test_free.cpp:102:23:102:23 | a | test_free.cpp:101:10:101:10 | a | test_free.cpp:102:23:102:23 | a | Memory may have been previously freed by $@. | test_free.cpp:101:5:101:8 | call to free | call to free |
5461
| test_free.cpp:153:5:153:5 | a | test_free.cpp:152:27:152:27 | a | test_free.cpp:153:5:153:5 | a | Memory may have been previously freed by $@. | test_free.cpp:152:22:152:25 | call to free | call to free |

cpp/ql/test/query-tests/Critical/MemoryFreed/test_free.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void test_new1() {
8888
void test_dereference1(A *a) {
8989
a->f(); // GOOD
9090
free(a);
91-
a->f(); // BAD [NOT DETECTED]
91+
a->f(); // BAD
9292
}
9393

9494
void* use_after_free(void *a) {

0 commit comments

Comments
 (0)