Skip to content

Commit 90b06c2

Browse files
committed
C++: Switch the source of use-after-free and double-free to be post-update nodes.
1 parent 5bb2144 commit 90b06c2

File tree

6 files changed

+139
-116
lines changed

6 files changed

+139
-116
lines changed

cpp/ql/src/Critical/DoubleFree.ql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import semmle.code.cpp.dataflow.new.DataFlow
1616
import FlowAfterFree
1717
import DoubleFree::PathGraph
1818

19-
predicate isFree(DataFlow::Node n, Expr e) { isFree(n, e, _) }
19+
predicate isFree(DataFlow::Node n, Expr e) {
20+
n.asExpr() = e and
21+
isFree(_, e, _)
22+
}
2023

2124
/**
2225
* `dealloc1` is a deallocation expression and `e` is an expression such

cpp/ql/src/Critical/FlowAfterFree.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ predicate isFree(DataFlow::Node n, Expr e, DeallocationExpr dealloc) {
101101
exists(Expr conv |
102102
e = conv.getUnconverted() and
103103
conv = dealloc.getFreedExpr().getFullyConverted() and
104-
conv = n.asConvertedExpr()
104+
conv = n.(DataFlow::PostUpdateNode).getPreUpdateNode().asConvertedExpr()
105105
) and
106106
// Ignore realloc functions
107107
not exists(dealloc.(FunctionCall).getTarget().(AllocationFunction).getReallocPtrArg())
Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,56 @@
11
edges
2-
| test_free.cpp:11:10:11:10 | a | test_free.cpp:14:10:14:10 | a |
3-
| test_free.cpp:30:10:30:10 | a | test_free.cpp:31:27:31:27 | a |
4-
| test_free.cpp:35:10:35:10 | a | test_free.cpp:37:27:37:27 | a |
5-
| test_free.cpp:42:27:42:27 | a | test_free.cpp:46:10:46:10 | a |
6-
| test_free.cpp:44:27:44:27 | a | test_free.cpp:46:10:46:10 | a |
7-
| test_free.cpp:50:27:50:27 | a | test_free.cpp:51:10:51:10 | a |
8-
| test_free.cpp:69:10:69:10 | a | test_free.cpp:72:14:72:14 | a |
9-
| test_free.cpp:83:12:83:12 | a | test_free.cpp:85:12:85:12 | a |
10-
| test_free.cpp:101:10:101:10 | a | test_free.cpp:103:10:103:10 | a |
11-
| test_free.cpp:128:10:128:11 | * ... | test_free.cpp:129:10:129:11 | * ... |
12-
| test_free.cpp:152:27:152:27 | a | test_free.cpp:154:10:154:10 | a |
13-
| test_free.cpp:207:10:207:10 | a | test_free.cpp:209:10:209:10 | a |
2+
| test_free.cpp:11:10:11:10 | pointer to free output argument | test_free.cpp:14:10:14:10 | a |
3+
| test_free.cpp:30:10:30:10 | pointer to free output argument | test_free.cpp:31:27:31:27 | a |
4+
| test_free.cpp:35:10:35:10 | pointer to free output argument | test_free.cpp:37:27:37:27 | a |
5+
| test_free.cpp:42:27:42:27 | pointer to free output argument | test_free.cpp:46:10:46:10 | a |
6+
| test_free.cpp:44:27:44:27 | pointer to free output argument | test_free.cpp:46:10:46:10 | a |
7+
| test_free.cpp:50:27:50:27 | pointer to free output argument | test_free.cpp:51:10:51:10 | a |
8+
| test_free.cpp:69:10:69:10 | pointer to free output argument | test_free.cpp:72:14:72:14 | a |
9+
| test_free.cpp:83:12:83:12 | pointer to operator delete output argument | test_free.cpp:85:12:85:12 | a |
10+
| test_free.cpp:101:10:101:10 | pointer to free output argument | test_free.cpp:103:10:103:10 | a |
11+
| test_free.cpp:128:10:128:11 | pointer to free output argument | test_free.cpp:129:10:129:11 | * ... |
12+
| test_free.cpp:131:10:131:13 | pointer to free output argument | test_free.cpp:132:10:132:13 | access to array |
13+
| test_free.cpp:152:27:152:27 | pointer to free output argument | test_free.cpp:154:10:154:10 | a |
14+
| test_free.cpp:207:10:207:10 | pointer to free output argument | test_free.cpp:209:10:209:10 | a |
1415
nodes
15-
| test_free.cpp:11:10:11:10 | a | semmle.label | a |
16+
| test_free.cpp:11:10:11:10 | pointer to free output argument | semmle.label | pointer to free output argument |
1617
| test_free.cpp:14:10:14:10 | a | semmle.label | a |
17-
| test_free.cpp:30:10:30:10 | a | semmle.label | a |
18+
| test_free.cpp:30:10:30:10 | pointer to free output argument | semmle.label | pointer to free output argument |
1819
| test_free.cpp:31:27:31:27 | a | semmle.label | a |
19-
| test_free.cpp:35:10:35:10 | a | semmle.label | a |
20+
| test_free.cpp:35:10:35:10 | pointer to free output argument | semmle.label | pointer to free output argument |
2021
| test_free.cpp:37:27:37:27 | a | semmle.label | a |
21-
| test_free.cpp:42:27:42:27 | a | semmle.label | a |
22-
| test_free.cpp:44:27:44:27 | a | semmle.label | a |
22+
| test_free.cpp:42:27:42:27 | pointer to free output argument | semmle.label | pointer to free output argument |
23+
| test_free.cpp:44:27:44:27 | pointer to free output argument | semmle.label | pointer to free output argument |
2324
| test_free.cpp:46:10:46:10 | a | semmle.label | a |
2425
| test_free.cpp:46:10:46:10 | a | semmle.label | a |
25-
| test_free.cpp:50:27:50:27 | a | semmle.label | a |
26+
| test_free.cpp:50:27:50:27 | pointer to free output argument | semmle.label | pointer to free output argument |
2627
| test_free.cpp:51:10:51:10 | a | semmle.label | a |
27-
| test_free.cpp:69:10:69:10 | a | semmle.label | a |
28+
| test_free.cpp:69:10:69:10 | pointer to free output argument | semmle.label | pointer to free output argument |
2829
| test_free.cpp:72:14:72:14 | a | semmle.label | a |
29-
| test_free.cpp:83:12:83:12 | a | semmle.label | a |
30+
| test_free.cpp:83:12:83:12 | pointer to operator delete output argument | semmle.label | pointer to operator delete output argument |
3031
| test_free.cpp:85:12:85:12 | a | semmle.label | a |
31-
| test_free.cpp:101:10:101:10 | a | semmle.label | a |
32+
| test_free.cpp:101:10:101:10 | pointer to free output argument | semmle.label | pointer to free output argument |
3233
| test_free.cpp:103:10:103:10 | a | semmle.label | a |
33-
| test_free.cpp:128:10:128:11 | * ... | semmle.label | * ... |
34+
| test_free.cpp:128:10:128:11 | pointer to free output argument | semmle.label | pointer to free output argument |
3435
| test_free.cpp:129:10:129:11 | * ... | semmle.label | * ... |
35-
| test_free.cpp:152:27:152:27 | a | semmle.label | a |
36+
| test_free.cpp:131:10:131:13 | pointer to free output argument | semmle.label | pointer to free output argument |
37+
| test_free.cpp:132:10:132:13 | access to array | semmle.label | access to array |
38+
| test_free.cpp:152:27:152:27 | pointer to free output argument | semmle.label | pointer to free output argument |
3639
| test_free.cpp:154:10:154:10 | a | semmle.label | a |
37-
| test_free.cpp:207:10:207:10 | a | semmle.label | a |
40+
| test_free.cpp:207:10:207:10 | pointer to free output argument | semmle.label | pointer to free output argument |
3841
| test_free.cpp:209:10:209:10 | a | semmle.label | a |
3942
subpaths
4043
#select
41-
| test_free.cpp:14:10:14:10 | a | test_free.cpp:11:10:11:10 | a | test_free.cpp:14:10:14:10 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:11:5:11:8 | call to free | call to free |
42-
| test_free.cpp:31:27:31:27 | a | test_free.cpp:30:10:30:10 | a | test_free.cpp:31:27:31:27 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:30:5:30:8 | call to free | call to free |
43-
| test_free.cpp:37:27:37:27 | a | test_free.cpp:35:10:35:10 | a | test_free.cpp:37:27:37:27 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:35:5:35:8 | call to free | call to free |
44-
| test_free.cpp:46:10:46:10 | a | test_free.cpp:42:27:42:27 | a | test_free.cpp:46:10:46:10 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:42:22:42:25 | call to free | call to free |
45-
| test_free.cpp:46:10:46:10 | a | test_free.cpp:44:27:44:27 | a | test_free.cpp:46:10:46:10 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:44:22:44:25 | call to free | call to free |
46-
| test_free.cpp:51:10:51:10 | a | test_free.cpp:50:27:50:27 | a | test_free.cpp:51:10:51:10 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:50:22:50:25 | call to free | call to free |
47-
| test_free.cpp:72:14:72:14 | a | test_free.cpp:69:10:69:10 | a | test_free.cpp:72:14:72:14 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:69:5:69:8 | call to free | call to free |
48-
| test_free.cpp:85:12:85:12 | a | test_free.cpp:83:12:83:12 | a | test_free.cpp:85:12:85:12 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:83:5:83:13 | delete | delete |
49-
| test_free.cpp:103:10:103:10 | a | test_free.cpp:101:10:101:10 | a | test_free.cpp:103:10:103:10 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:101:5:101:8 | call to free | call to free |
50-
| test_free.cpp:129:10:129:11 | * ... | test_free.cpp:128:10:128:11 | * ... | test_free.cpp:129:10:129:11 | * ... | Memory pointed to by '* ...' may already have been freed by $@. | test_free.cpp:128:5:128:8 | call to free | call to free |
51-
| test_free.cpp:154:10:154:10 | a | test_free.cpp:152:27:152:27 | a | test_free.cpp:154:10:154:10 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:152:22:152:25 | call to free | call to free |
52-
| test_free.cpp:209:10:209:10 | a | test_free.cpp:207:10:207:10 | a | test_free.cpp:209:10:209:10 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:207:5:207:8 | call to free | call to free |
44+
| test_free.cpp:14:10:14:10 | a | test_free.cpp:11:10:11:10 | pointer to free output argument | test_free.cpp:14:10:14:10 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:11:5:11:8 | call to free | call to free |
45+
| test_free.cpp:31:27:31:27 | a | test_free.cpp:30:10:30:10 | pointer to free output argument | test_free.cpp:31:27:31:27 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:30:5:30:8 | call to free | call to free |
46+
| test_free.cpp:37:27:37:27 | a | test_free.cpp:35:10:35:10 | pointer to free output argument | test_free.cpp:37:27:37:27 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:35:5:35:8 | call to free | call to free |
47+
| test_free.cpp:46:10:46:10 | a | test_free.cpp:42:27:42:27 | pointer to free output argument | test_free.cpp:46:10:46:10 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:42:22:42:25 | call to free | call to free |
48+
| test_free.cpp:46:10:46:10 | a | test_free.cpp:44:27:44:27 | pointer to free output argument | test_free.cpp:46:10:46:10 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:44:22:44:25 | call to free | call to free |
49+
| test_free.cpp:51:10:51:10 | a | test_free.cpp:50:27:50:27 | pointer to free output argument | test_free.cpp:51:10:51:10 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:50:22:50:25 | call to free | call to free |
50+
| test_free.cpp:72:14:72:14 | a | test_free.cpp:69:10:69:10 | pointer to free output argument | test_free.cpp:72:14:72:14 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:69:5:69:8 | call to free | call to free |
51+
| test_free.cpp:85:12:85:12 | a | test_free.cpp:83:12:83:12 | pointer to operator delete output argument | test_free.cpp:85:12:85:12 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:83:5:83:13 | delete | delete |
52+
| test_free.cpp:103:10:103:10 | a | test_free.cpp:101:10:101:10 | pointer to free output argument | test_free.cpp:103:10:103:10 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:101:5:101:8 | call to free | call to free |
53+
| test_free.cpp:129:10:129:11 | * ... | test_free.cpp:128:10:128:11 | pointer to free output argument | test_free.cpp:129:10:129:11 | * ... | Memory pointed to by '* ...' may already have been freed by $@. | test_free.cpp:128:5:128:8 | call to free | call to free |
54+
| test_free.cpp:132:10:132:13 | access to array | test_free.cpp:131:10:131:13 | pointer to free output argument | test_free.cpp:132:10:132:13 | access to array | Memory pointed to by 'access to array' may already have been freed by $@. | test_free.cpp:131:5:131:8 | call to free | call to free |
55+
| test_free.cpp:154:10:154:10 | a | test_free.cpp:152:27:152:27 | pointer to free output argument | test_free.cpp:154:10:154:10 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:152:22:152:25 | call to free | call to free |
56+
| test_free.cpp:209:10:209:10 | a | test_free.cpp:207:10:207:10 | pointer to free output argument | test_free.cpp:209:10:209:10 | a | Memory pointed to by 'a' may already have been freed by $@. | test_free.cpp:207:5:207:8 | call to free | call to free |

0 commit comments

Comments
 (0)