Skip to content

Commit defbbb2

Browse files
committed
Rust: Add additional models for stdlib and sqlx
1 parent aab3428 commit defbbb2

File tree

11 files changed

+163
-21
lines changed

11 files changed

+163
-21
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/rust-all
4+
extensible: summaryModel
5+
data:
6+
- ["repo:https://github.com/seanmonstar/reqwest:reqwest", "<crate::blocking::response::Response>::text", "Argument[self]", "ReturnValue", "taint", "manual"]

rust/ql/lib/codeql/rust/frameworks/stdlib/lang-core.model.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,17 @@ extensions:
33
pack: codeql/rust-all
44
extensible: summaryModel
55
data:
6+
# Option
67
- ["lang:core", "<crate::option::Option>::unwrap", "Argument[self].Variant[crate::option::Option::Some(0)]", "ReturnValue", "value", "manual"]
8+
- ["lang:core", "<crate::option::Option>::unwrap", "Argument[self]", "ReturnValue", "taint", "manual"]
9+
- ["lang:core", "<crate::option::Option>::unwrap_or", "Argument[self].Variant[crate::option::Option::Some(0)]", "ReturnValue", "value", "manual"]
10+
- ["lang:core", "<crate::option::Option>::unwrap_or", "Argument[0]", "ReturnValue", "value", "manual"]
11+
- ["lang:core", "<crate::option::Option>::unwrap_or", "Argument[self]", "ReturnValue", "taint", "manual"]
12+
# Result
13+
- ["lang:core", "<crate::result::Result>::unwrap", "Argument[self].Variant[crate::result::Result::Ok(0)]", "ReturnValue", "value", "manual"]
14+
- ["lang:core", "<crate::result::Result>::unwrap", "Argument[self]", "ReturnValue", "taint", "manual"]
15+
- ["lang:core", "<crate::result::Result>::unwrap_or", "Argument[self].Variant[crate::result::Result::Ok(0)]", "ReturnValue", "value", "manual"]
16+
- ["lang:core", "<crate::result::Result>::unwrap_or", "Argument[0]", "ReturnValue", "value", "manual"]
17+
- ["lang:core", "<crate::result::Result>::unwrap_or", "Argument[self]", "ReturnValue", "taint", "manual"]
18+
# String
19+
- ["lang:alloc", "<crate::string::String>::as_str", "Argument[self]", "ReturnValue", "taint", "manual"]

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,11 @@ localStep
207207
| main.rs:229:9:229:10 | [SSA] s1 | main.rs:230:10:230:11 | s1 |
208208
| main.rs:229:9:229:10 | s1 | main.rs:229:9:229:10 | [SSA] s1 |
209209
| main.rs:229:14:229:29 | Some(...) | main.rs:229:9:229:10 | s1 |
210+
| main.rs:230:23:230:23 | 0 | main.rs:230:10:230:24 | s1.unwrap_or(...) |
210211
| main.rs:232:9:232:10 | [SSA] s2 | main.rs:233:10:233:11 | s2 |
211212
| main.rs:232:9:232:10 | s2 | main.rs:232:9:232:10 | [SSA] s2 |
212213
| main.rs:232:14:232:20 | Some(...) | main.rs:232:9:232:10 | s2 |
214+
| main.rs:233:23:233:32 | source(...) | main.rs:233:10:233:33 | s2.unwrap_or(...) |
213215
| main.rs:237:9:237:10 | [SSA] s1 | main.rs:239:14:239:15 | s1 |
214216
| main.rs:237:9:237:10 | s1 | main.rs:237:9:237:10 | [SSA] s1 |
215217
| main.rs:237:14:237:29 | Some(...) | main.rs:237:9:237:10 | s1 |
@@ -529,6 +531,9 @@ storeStep
529531
| main.rs:407:27:407:27 | 0 | Some | main.rs:407:22:407:28 | Some(...) |
530532
readStep
531533
| file://:0:0:0:0 | [summary param] self in lang:core::_::<crate::option::Option>::unwrap | Some | file://:0:0:0:0 | [summary] read: Argument[self].Variant[crate::option::Option::Some(0)] in lang:core::_::<crate::option::Option>::unwrap |
534+
| file://:0:0:0:0 | [summary param] self in lang:core::_::<crate::option::Option>::unwrap_or | Some | file://:0:0:0:0 | [summary] read: Argument[self].Variant[crate::option::Option::Some(0)] in lang:core::_::<crate::option::Option>::unwrap_or |
535+
| file://:0:0:0:0 | [summary param] self in lang:core::_::<crate::result::Result>::unwrap | Ok | file://:0:0:0:0 | [summary] read: Argument[self].Variant[crate::result::Result::Ok(0)] in lang:core::_::<crate::result::Result>::unwrap |
536+
| file://:0:0:0:0 | [summary param] self in lang:core::_::<crate::result::Result>::unwrap_or | Ok | file://:0:0:0:0 | [summary] read: Argument[self].Variant[crate::result::Result::Ok(0)] in lang:core::_::<crate::result::Result>::unwrap_or |
532537
| main.rs:33:9:33:15 | Some(...) | Some | main.rs:33:14:33:14 | _ |
533538
| main.rs:87:11:87:11 | i | &ref | main.rs:87:10:87:11 | * ... |
534539
| main.rs:95:10:95:10 | a | tuple.0 | main.rs:95:10:95:12 | a.0 |

rust/ql/test/library-tests/dataflow/local/inline-flow.expected

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
models
22
| 1 | Summary: lang:core; <crate::option::Option>::unwrap; Argument[self].Variant[crate::option::Option::Some(0)]; ReturnValue; value |
3+
| 2 | Summary: lang:core; <crate::option::Option>::unwrap_or; Argument[0]; ReturnValue; value |
4+
| 3 | Summary: lang:core; <crate::option::Option>::unwrap_or; Argument[self].Variant[crate::option::Option::Some(0)]; ReturnValue; value |
35
edges
46
| main.rs:19:13:19:21 | source(...) | main.rs:20:10:20:10 | s | provenance | |
57
| main.rs:24:13:24:21 | source(...) | main.rs:27:10:27:10 | c | provenance | |
@@ -37,6 +39,10 @@ edges
3739
| main.rs:224:14:224:29 | Some(...) [Some] | main.rs:225:10:225:11 | s1 [Some] | provenance | |
3840
| main.rs:224:19:224:28 | source(...) | main.rs:224:14:224:29 | Some(...) [Some] | provenance | |
3941
| main.rs:225:10:225:11 | s1 [Some] | main.rs:225:10:225:20 | s1.unwrap(...) | provenance | MaD:1 |
42+
| main.rs:229:14:229:29 | Some(...) [Some] | main.rs:230:10:230:11 | s1 [Some] | provenance | |
43+
| main.rs:229:19:229:28 | source(...) | main.rs:229:14:229:29 | Some(...) [Some] | provenance | |
44+
| main.rs:230:10:230:11 | s1 [Some] | main.rs:230:10:230:24 | s1.unwrap_or(...) | provenance | MaD:3 |
45+
| main.rs:233:23:233:32 | source(...) | main.rs:233:10:233:33 | s2.unwrap_or(...) | provenance | MaD:2 |
4046
| main.rs:237:14:237:29 | Some(...) [Some] | main.rs:239:14:239:15 | s1 [Some] | provenance | |
4147
| main.rs:237:19:237:28 | source(...) | main.rs:237:14:237:29 | Some(...) [Some] | provenance | |
4248
| main.rs:239:14:239:15 | s1 [Some] | main.rs:239:14:239:16 | TryExpr | provenance | |
@@ -150,6 +156,12 @@ nodes
150156
| main.rs:224:19:224:28 | source(...) | semmle.label | source(...) |
151157
| main.rs:225:10:225:11 | s1 [Some] | semmle.label | s1 [Some] |
152158
| main.rs:225:10:225:20 | s1.unwrap(...) | semmle.label | s1.unwrap(...) |
159+
| main.rs:229:14:229:29 | Some(...) [Some] | semmle.label | Some(...) [Some] |
160+
| main.rs:229:19:229:28 | source(...) | semmle.label | source(...) |
161+
| main.rs:230:10:230:11 | s1 [Some] | semmle.label | s1 [Some] |
162+
| main.rs:230:10:230:24 | s1.unwrap_or(...) | semmle.label | s1.unwrap_or(...) |
163+
| main.rs:233:10:233:33 | s2.unwrap_or(...) | semmle.label | s2.unwrap_or(...) |
164+
| main.rs:233:23:233:32 | source(...) | semmle.label | source(...) |
153165
| main.rs:237:14:237:29 | Some(...) [Some] | semmle.label | Some(...) [Some] |
154166
| main.rs:237:19:237:28 | source(...) | semmle.label | source(...) |
155167
| main.rs:239:14:239:15 | s1 [Some] | semmle.label | s1 [Some] |
@@ -240,6 +252,8 @@ testFailures
240252
| main.rs:201:33:201:33 | n | main.rs:198:27:198:36 | source(...) | main.rs:201:33:201:33 | n | $@ | main.rs:198:27:198:36 | source(...) | source(...) |
241253
| main.rs:214:25:214:25 | n | main.rs:211:19:211:28 | source(...) | main.rs:214:25:214:25 | n | $@ | main.rs:211:19:211:28 | source(...) | source(...) |
242254
| main.rs:225:10:225:20 | s1.unwrap(...) | main.rs:224:19:224:28 | source(...) | main.rs:225:10:225:20 | s1.unwrap(...) | $@ | main.rs:224:19:224:28 | source(...) | source(...) |
255+
| main.rs:230:10:230:24 | s1.unwrap_or(...) | main.rs:229:19:229:28 | source(...) | main.rs:230:10:230:24 | s1.unwrap_or(...) | $@ | main.rs:229:19:229:28 | source(...) | source(...) |
256+
| main.rs:233:10:233:33 | s2.unwrap_or(...) | main.rs:233:23:233:32 | source(...) | main.rs:233:10:233:33 | s2.unwrap_or(...) | $@ | main.rs:233:23:233:32 | source(...) | source(...) |
243257
| main.rs:240:10:240:11 | i1 | main.rs:237:19:237:28 | source(...) | main.rs:240:10:240:11 | i1 | $@ | main.rs:237:19:237:28 | source(...) | source(...) |
244258
| main.rs:251:10:251:11 | i1 | main.rs:246:35:246:44 | source(...) | main.rs:251:10:251:11 | i1 | $@ | main.rs:246:35:246:44 | source(...) | source(...) |
245259
| main.rs:267:35:267:35 | n | main.rs:264:29:264:38 | source(...) | main.rs:267:35:267:35 | n | $@ | main.rs:264:29:264:38 | source(...) | source(...) |

rust/ql/test/library-tests/dataflow/local/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,10 @@ fn option_unwrap() {
227227

228228
fn option_unwrap_or() {
229229
let s1 = Some(source(46));
230-
sink(s1.unwrap_or(0)); // $ MISSING: hasValueFlow=46
230+
sink(s1.unwrap_or(0)); // $ hasValueFlow=46
231231

232232
let s2 = Some(0);
233-
sink(s2.unwrap_or(source(47))); // $ MISSING: hasValueFlow=47
233+
sink(s2.unwrap_or(source(47))); // $ hasValueFlow=47
234234
}
235235

236236
fn option_questionmark() -> Option<i64> {

rust/ql/test/library-tests/dataflow/sources/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn test_env_vars() {
1212
let var2 = std::env::var_os("PATH").unwrap(); // $ Alert[rust/summary/taint-sources]
1313

1414
sink(var1); // $ MISSING: hasTaintFlow
15-
sink(var2); // $ MISSING: hasTaintFlow
15+
sink(var2); // $ hasTaintFlow
1616

1717
for (key, value) in std::env::vars() { // $ Alert[rust/summary/taint-sources]
1818
sink(key); // $ MISSING: hasTaintFlow
@@ -61,7 +61,7 @@ async fn test_reqwest() -> Result<(), reqwest::Error> {
6161
sink(remote_string1); // $ MISSING: hasTaintFlow
6262

6363
let remote_string2 = reqwest::blocking::get("http://example.com/").unwrap().text().unwrap(); // $ Alert[rust/summary/taint-sources]
64-
sink(remote_string2); // $ MISSING: hasTaintFlow
64+
sink(remote_string2); // $ hasTaintFlow
6565

6666
let remote_string3 = reqwest::get("http://example.com/").await?.text().await?; // $ Alert[rust/summary/taint-sources]
6767
sink(remote_string3); // $ MISSING: hasTaintFlow

rust/ql/test/library-tests/dataflow/strings/inline-taint-flow.expected

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
models
2+
| 1 | Summary: lang:alloc; <crate::string::String>::as_str; Argument[self]; ReturnValue; taint |
23
edges
34
| main.rs:20:13:20:22 | source(...) | main.rs:21:19:21:25 | s[...] | provenance | |
45
| main.rs:20:13:20:22 | source(...) | main.rs:22:16:22:21 | sliced | provenance | |
56
| main.rs:21:18:21:25 | &... [&ref] | main.rs:22:16:22:21 | sliced | provenance | |
67
| main.rs:21:19:21:25 | s[...] | main.rs:21:18:21:25 | &... [&ref] | provenance | |
78
| main.rs:26:14:26:23 | source(...) | main.rs:32:10:32:11 | s4 | provenance | |
89
| main.rs:37:14:37:23 | source(...) | main.rs:40:10:40:35 | ... + ... | provenance | |
10+
| main.rs:57:13:57:22 | source(...) | main.rs:58:16:58:16 | s | provenance | |
11+
| main.rs:58:16:58:16 | s | main.rs:58:16:58:25 | s.as_str(...) | provenance | MaD:1 |
912
nodes
1013
| main.rs:20:13:20:22 | source(...) | semmle.label | source(...) |
1114
| main.rs:21:18:21:25 | &... [&ref] | semmle.label | &... [&ref] |
@@ -15,9 +18,13 @@ nodes
1518
| main.rs:32:10:32:11 | s4 | semmle.label | s4 |
1619
| main.rs:37:14:37:23 | source(...) | semmle.label | source(...) |
1720
| main.rs:40:10:40:35 | ... + ... | semmle.label | ... + ... |
21+
| main.rs:57:13:57:22 | source(...) | semmle.label | source(...) |
22+
| main.rs:58:16:58:16 | s | semmle.label | s |
23+
| main.rs:58:16:58:25 | s.as_str(...) | semmle.label | s.as_str(...) |
1824
subpaths
1925
testFailures
2026
#select
2127
| main.rs:22:16:22:21 | sliced | main.rs:20:13:20:22 | source(...) | main.rs:22:16:22:21 | sliced | $@ | main.rs:20:13:20:22 | source(...) | source(...) |
2228
| main.rs:32:10:32:11 | s4 | main.rs:26:14:26:23 | source(...) | main.rs:32:10:32:11 | s4 | $@ | main.rs:26:14:26:23 | source(...) | source(...) |
2329
| main.rs:40:10:40:35 | ... + ... | main.rs:37:14:37:23 | source(...) | main.rs:40:10:40:35 | ... + ... | $@ | main.rs:37:14:37:23 | source(...) | source(...) |
30+
| main.rs:58:16:58:25 | s.as_str(...) | main.rs:57:13:57:22 | source(...) | main.rs:58:16:58:25 | s.as_str(...) | $@ | main.rs:57:13:57:22 | source(...) | source(...) |

rust/ql/test/library-tests/dataflow/strings/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn string_to_string() {
5555

5656
fn as_str() {
5757
let s = source(67);
58-
sink_slice(s.as_str()); // $ MISSING: hasTaintFlow=67
58+
sink_slice(s.as_str()); // $ hasTaintFlow=67
5959
}
6060

6161
fn string_format() {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
| 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:11 |
2+
| file://:0:0:0:0 | [summary param] self in lang:core::_::<crate::option::Option>::unwrap | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:core::_::<crate::option::Option>::unwrap | MaD:2 |
3+
| file://:0:0:0:0 | [summary param] self in lang:core::_::<crate::option::Option>::unwrap_or | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:core::_::<crate::option::Option>::unwrap_or | MaD:5 |
4+
| file://:0:0:0:0 | [summary param] self in lang:core::_::<crate::result::Result>::unwrap | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:core::_::<crate::result::Result>::unwrap | MaD:7 |
5+
| file://:0:0:0:0 | [summary param] self in lang:core::_::<crate::result::Result>::unwrap_or | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:core::_::<crate::result::Result>::unwrap_or | MaD:10 |
6+
| 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 in repo:https://github.com/seanmonstar/reqwest:reqwest::_::<crate::blocking::response::Response>::text | MaD:0 |
17
| main.rs:4:5:4:8 | 1000 | main.rs:4:5:4:12 | ... + ... | |
28
| main.rs:4:12:4:12 | i | main.rs:4:5:4:12 | ... + ... | |
39
| main.rs:13:10:13:10 | a | main.rs:13:10:13:14 | ... + ... | |

0 commit comments

Comments
 (0)