Skip to content

Commit 55186c8

Browse files
committed
Rust: Translate more MaD IDs in tests
1 parent 9286596 commit 55186c8

File tree

6 files changed

+522
-470
lines changed

6 files changed

+522
-470
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
private import codeql.dataflow.test.ProvenancePathGraph as Graph
2+
private import codeql.rust.dataflow.internal.ModelsAsData as MaD
3+
4+
signature predicate provenanceSig(string model);
5+
6+
module TranslateModels<provenanceSig/1 provenance> {
7+
import Graph::TranslateModels<MaD::interpretModelForTest/2, provenance/1>
8+
}

rust/ql/test/library-tests/dataflow/local/DataFlowStep.expected

Lines changed: 476 additions & 464 deletions
Large diffs are not rendered by default.

rust/ql/test/library-tests/dataflow/local/DataFlowStep.ql

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
import codeql.rust.dataflow.DataFlow
22
import codeql.rust.dataflow.internal.DataFlowImpl
3+
import utils.test.TranslateModels
34

4-
query predicate localStep = DataFlow::localFlowStep/2;
5+
private predicate provenance(string model) { RustDataFlow::simpleLocalFlowStep(_, _, model) }
6+
7+
private module Tm = TranslateModels<provenance/1>;
8+
9+
query predicate models = Tm::models/2;
10+
11+
query predicate localStep(Node nodeFrom, Node nodeTo, string model) {
12+
exists(string madId |
13+
RustDataFlow::simpleLocalFlowStep(nodeFrom, nodeTo, madId) and
14+
Tm::translateModels(madId, model)
15+
)
16+
}
517

618
query predicate storeStep = RustDataFlow::storeStep/3;
719

rust/ql/test/library-tests/dataflow/taint/TaintFlowStep.expected

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
| file://:0:0:0:0 | [summary param] 0 in lang:alloc::_::crate::fmt::format | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::crate::fmt::format | MaD:35 |
2-
| file://:0:0:0:0 | [summary param] self in lang:alloc::_::<crate::string::String>::as_str | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::<crate::string::String>::as_str | MaD:33 |
3-
| file://:0:0:0:0 | [summary param] self in repo:https://github.com/seanmonstar/reqwest:reqwest::_::<crate::blocking::response::Response>::text | file://:0:0:0:0 | [summary] to write: ReturnValue.Variant[crate::result::Result::Ok(0)] in repo:https://github.com/seanmonstar/reqwest:reqwest::_::<crate::blocking::response::Response>::text | MaD:12 |
1+
additionalTaintStep
2+
| file://:0:0:0:0 | [summary param] 0 in lang:alloc::_::crate::fmt::format | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::crate::fmt::format | MaD:2 |
3+
| file://:0:0:0:0 | [summary param] self in lang:alloc::_::<crate::string::String>::as_str | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::<crate::string::String>::as_str | MaD:1 |
4+
| file://:0:0:0:0 | [summary param] self in repo:https://github.com/seanmonstar/reqwest:reqwest::_::<crate::blocking::response::Response>::text | file://:0:0:0:0 | [summary] to write: ReturnValue.Variant[crate::result::Result::Ok(0)] in repo:https://github.com/seanmonstar/reqwest:reqwest::_::<crate::blocking::response::Response>::text | MaD:3 |
45
| main.rs:4:5:4:8 | 1000 | main.rs:4:5:4:12 | ... + ... | |
56
| main.rs:4:12:4:12 | i | main.rs:4:5:4:12 | ... + ... | |
67
| main.rs:8:20:8:20 | s | main.rs:8:14:8:20 | FormatArgsExpr | |
@@ -17,3 +18,7 @@
1718
| main.rs:64:24:64:24 | s | main.rs:64:24:64:27 | s[1] | |
1819
| main.rs:64:24:64:27 | s[1] | main.rs:64:18:64:27 | FormatArgsExpr | |
1920
| main.rs:69:9:69:12 | arr2 | main.rs:69:9:69:15 | arr2[1] | |
21+
models
22+
| 1 | Summary: lang:alloc; <crate::string::String>::as_str; Argument[self]; ReturnValue; taint |
23+
| 2 | Summary: lang:alloc; crate::fmt::format; Argument[0]; ReturnValue; taint |
24+
| 3 | Summary: repo:https://github.com/seanmonstar/reqwest:reqwest; <crate::blocking::response::Response>::text; Argument[self]; ReturnValue.Variant[crate::result::Result::Ok(0)]; taint |
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
import codeql.rust.dataflow.DataFlow
22
import codeql.rust.dataflow.internal.TaintTrackingImpl
3+
import utils.test.TranslateModels
34

4-
query predicate additionalTaintStep = RustTaintTracking::defaultAdditionalTaintStep/3;
5+
private predicate provenance(string model) {
6+
RustTaintTracking::defaultAdditionalTaintStep(_, _, model)
7+
}
8+
9+
private module Tm = TranslateModels<provenance/1>;
10+
11+
query predicate models = Tm::models/2;
12+
13+
query predicate additionalTaintStep(DataFlow::Node pred, DataFlow::Node succ, string model) {
14+
exists(string madId |
15+
RustTaintTracking::defaultAdditionalTaintStep(pred, succ, madId) and
16+
Tm::translateModels(madId, model)
17+
)
18+
}

shared/dataflow/codeql/dataflow/test/ProvenancePathGraph.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ signature class PathNodeSig {
1616

1717
private signature predicate provenanceSig(string model);
1818

19-
private module TranslateModels<
19+
/** Translates models-as-data provenance information into a format that can be used in tests. */
20+
module TranslateModels<
2021
interpretModelForTestSig/2 interpretModelForTest0, provenanceSig/1 provenance>
2122
{
2223
private predicate madIds(string madId) {

0 commit comments

Comments
 (0)