Skip to content

Commit 162ec28

Browse files
committed
C++: Also fix 'OverrunWriteProductFlow.ql'
1 parent 8056131 commit 162ec28

File tree

4 files changed

+46
-12
lines changed

4 files changed

+46
-12
lines changed

cpp/ql/src/experimental/Likely Bugs/ArrayAccessProductFlow.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ from
7474
DataFlow::PathNode sink1, DataFlow2::PathNode sink2
7575
where conf.hasFlowPath(source1, source2, sink1, sink2)
7676
// TODO: pull delta out and display it
77-
select sink1, source1, sink1, "off-by one error allocated at $@ bounded by $@", source1, source1,
78-
sink2, sink2
77+
select sink1.getNode(), source1, sink1, "off-by one error allocated at $@ bounded by $@", source1,
78+
source1.toString(), sink2, sink2.toString()

cpp/ql/src/experimental/Likely Bugs/OverrunWriteProductFlow.ql

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1+
/**
2+
* @id cpp/overrun-write
3+
* @kind path-problem
4+
*/
5+
16
import cpp
27
import experimental.semmle.code.cpp.dataflow.ProductFlow
38
import semmle.code.cpp.ir.IR
49
import semmle.code.cpp.valuenumbering.GlobalValueNumbering
510
import semmle.code.cpp.models.interfaces.Allocation
611
import semmle.code.cpp.models.interfaces.ArrayFunction
12+
import DataFlow::PathGraph
713

814
class StringSizeConfiguration extends ProductFlow::Configuration {
915
StringSizeConfiguration() { this = "StringSizeConfiguration" }
1016

1117
override predicate isSourcePair(DataFlow::Node bufSource, DataFlow::Node sizeSource) {
12-
exists(
13-
GVN sizeGvn // TODO: use-use flow instead of GVN
14-
|
15-
bufSource.asConvertedExpr().(AllocationExpr).getSizeExpr() = sizeGvn.getAnExpr() and
16-
sizeSource.asConvertedExpr() = sizeGvn.getAnExpr()
17-
)
18+
bufSource.asConvertedExpr().(AllocationExpr).getSizeExpr() = sizeSource.asConvertedExpr()
1819
}
1920

2021
override predicate isSinkPair(DataFlow::Node bufSink, DataFlow::Node sizeSink) {
@@ -31,4 +32,6 @@ from
3132
StringSizeConfiguration conf, DataFlow::PathNode source1, DataFlow2::PathNode source2,
3233
DataFlow::PathNode sink1, DataFlow2::PathNode sink2
3334
where conf.hasFlowPath(source1, source2, sink1, sink2)
34-
select source1, source2, sink1, sink2
35+
// TODO: pull delta out and display it
36+
select sink1.getNode(), source1, sink1, "overrunning write allocated at $@ bounded by $@", source1,
37+
source1.toString(), sink2, sink2.toString()
Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,33 @@
1-
| test.cpp:19:19:19:24 | call to malloc | test.cpp:18:17:18:20 | size | test.cpp:26:18:26:23 | Load | test.cpp:26:31:26:39 | Convert |
2-
| test.cpp:19:19:19:24 | call to malloc | test.cpp:18:17:18:20 | size | test.cpp:30:18:30:23 | Load | test.cpp:30:31:30:39 | Convert |
1+
edges
2+
| test.cpp:16:11:16:21 | VariableAddress indirection [string] | test.cpp:24:21:24:31 | Call indirection [string] |
3+
| test.cpp:16:11:16:21 | VariableAddress indirection [string] | test.cpp:34:21:34:31 | Call indirection [string] |
4+
| test.cpp:18:5:18:30 | Store | test.cpp:18:10:18:15 | Load indirection [post update] [string] |
5+
| test.cpp:18:10:18:15 | Load indirection [post update] [string] | test.cpp:16:11:16:21 | VariableAddress indirection [string] |
6+
| test.cpp:18:19:18:24 | call to malloc | test.cpp:18:5:18:30 | Store |
7+
| test.cpp:24:21:24:31 | Call indirection [string] | test.cpp:26:13:26:15 | Load indirection [string] |
8+
| test.cpp:26:13:26:15 | Load indirection [string] | test.cpp:26:18:26:23 | FieldAddress indirection |
9+
| test.cpp:26:18:26:23 | FieldAddress indirection | test.cpp:26:18:26:23 | Load |
10+
| test.cpp:29:32:29:34 | str indirection [string] | test.cpp:30:13:30:15 | Load indirection [string] |
11+
| test.cpp:30:13:30:15 | Load indirection [string] | test.cpp:30:18:30:23 | FieldAddress indirection |
12+
| test.cpp:30:18:30:23 | FieldAddress indirection | test.cpp:30:18:30:23 | Load |
13+
| test.cpp:34:21:34:31 | Call indirection [string] | test.cpp:35:21:35:23 | str indirection [string] |
14+
| test.cpp:35:21:35:23 | str indirection [string] | test.cpp:29:32:29:34 | str indirection [string] |
15+
nodes
16+
| test.cpp:16:11:16:21 | VariableAddress indirection [string] | semmle.label | VariableAddress indirection [string] |
17+
| test.cpp:18:5:18:30 | Store | semmle.label | Store |
18+
| test.cpp:18:10:18:15 | Load indirection [post update] [string] | semmle.label | Load indirection [post update] [string] |
19+
| test.cpp:18:19:18:24 | call to malloc | semmle.label | call to malloc |
20+
| test.cpp:24:21:24:31 | Call indirection [string] | semmle.label | Call indirection [string] |
21+
| test.cpp:26:13:26:15 | Load indirection [string] | semmle.label | Load indirection [string] |
22+
| test.cpp:26:18:26:23 | FieldAddress indirection | semmle.label | FieldAddress indirection |
23+
| test.cpp:26:18:26:23 | Load | semmle.label | Load |
24+
| test.cpp:29:32:29:34 | str indirection [string] | semmle.label | str indirection [string] |
25+
| test.cpp:30:13:30:15 | Load indirection [string] | semmle.label | Load indirection [string] |
26+
| test.cpp:30:18:30:23 | FieldAddress indirection | semmle.label | FieldAddress indirection |
27+
| test.cpp:30:18:30:23 | Load | semmle.label | Load |
28+
| test.cpp:34:21:34:31 | Call indirection [string] | semmle.label | Call indirection [string] |
29+
| test.cpp:35:21:35:23 | str indirection [string] | semmle.label | str indirection [string] |
30+
subpaths
31+
#select
32+
| test.cpp:26:18:26:23 | Load | test.cpp:18:19:18:24 | call to malloc | test.cpp:26:18:26:23 | Load | overrunning write allocated at $@ bounded by $@ | test.cpp:18:19:18:24 | call to malloc | call to malloc | test.cpp:26:31:26:39 | Convert | Convert |
33+
| test.cpp:30:18:30:23 | Load | test.cpp:18:19:18:24 | call to malloc | test.cpp:30:18:30:23 | Load | overrunning write allocated at $@ bounded by $@ | test.cpp:18:19:18:24 | call to malloc | call to malloc | test.cpp:30:31:30:39 | Convert | Convert |

cpp/ql/test/experimental/query-tests/Security/CWE/CWE-119/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ typedef struct
1515

1616
string_t *mk_string_t(int size) {
1717
string_t *str = (string_t *) malloc(sizeof(string_t));
18-
str->size = size;
1918
str->string = malloc(size);
19+
str->size = size;
2020
return str;
2121
}
2222

0 commit comments

Comments
 (0)