Skip to content

Commit 5ba331e

Browse files
committed
Rust: Splits off sources/net.
1 parent 7ddd441 commit 5ba331e

File tree

8 files changed

+2496
-15
lines changed

8 files changed

+2496
-15
lines changed

rust/ql/test/library-tests/dataflow/sources/net/Cargo.lock

Lines changed: 2146 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/test/library-tests/dataflow/sources/net/InlineFlow.expected

Lines changed: 278 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @kind path-problem
3+
*/
4+
5+
import rust
6+
import codeql.rust.dataflow.DataFlow
7+
import codeql.rust.Concepts
8+
import utils.test.InlineFlowTest
9+
10+
/**
11+
* Configuration for flow from any threat model source to an argument of the function `sink`.
12+
*/
13+
module MyFlowConfig implements DataFlow::ConfigSig {
14+
predicate isSource(DataFlow::Node source) { source instanceof ThreatModelSource }
15+
16+
predicate isSink(DataFlow::Node sink) {
17+
any(CallExpr call |
18+
call.getFunction().(PathExpr).getPath().getSegment().getIdentifier().getText() = "sink"
19+
).getArgList().getAnArg() = sink.asExpr().getExpr()
20+
}
21+
22+
predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) {
23+
// flow out from any content at the sink.
24+
isSink(node) and
25+
exists(c)
26+
}
27+
}
28+
29+
module MyFlowTest = TaintFlowTest<MyFlowConfig>;
30+
31+
import MyFlowTest
32+
import PathGraph
33+
34+
from PathNode source, PathNode sink
35+
where flowPath(source, sink)
36+
select sink, source, sink, "$@", source, source.toString()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
| test.rs:11:26:11:47 | ...::get | Flow source 'RemoteSource' of type remote (DEFAULT). |
2+
| test.rs:14:26:14:47 | ...::get | Flow source 'RemoteSource' of type remote (DEFAULT). |
3+
| test.rs:17:26:17:47 | ...::get | Flow source 'RemoteSource' of type remote (DEFAULT). |
4+
| test.rs:20:26:20:47 | ...::get | Flow source 'RemoteSource' of type remote (DEFAULT). |
5+
| test.rs:23:26:23:37 | ...::get | Flow source 'RemoteSource' of type remote (DEFAULT). |
6+
| test.rs:26:26:26:37 | ...::get | Flow source 'RemoteSource' of type remote (DEFAULT). |
7+
| test.rs:29:24:29:35 | ...::get | Flow source 'RemoteSource' of type remote (DEFAULT). |
8+
| test.rs:45:18:45:47 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
9+
| test.rs:60:31:60:42 | send_request | Flow source 'RemoteSource' of type remote (DEFAULT). |
10+
| test.rs:67:31:67:42 | send_request | Flow source 'RemoteSource' of type remote (DEFAULT). |
11+
| test.rs:155:26:155:53 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
12+
| test.rs:174:26:174:61 | ...::connect_timeout | Flow source 'RemoteSource' of type remote (DEFAULT). |
13+
| test.rs:224:28:224:57 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
14+
| test.rs:306:22:306:49 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
15+
| test.rs:332:22:332:50 | ...::new | Flow source 'RemoteSource' of type remote (DEFAULT). |
16+
| test.rs:359:16:359:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
17+
| test.rs:359:16:359:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
query: queries/summary/TaintSources.ql
2+
postprocess: utils/test/InlineExpectationsTestQuery.ql
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
qltest_cargo_check: true
2+
qltest_dependencies:
3+
- reqwest = { version = "0.12.9", features = ["blocking"] }
4+
- hyper = { version = "1.5.2", features = ["full"] }
5+
- hyper-util = { version = "0.1.10", features = ["full"] }
6+
- http-body-util = { version = "0.1.2" }
7+
- http = { version = "1.2.0" }
8+
- tokio = { version = "1.43.0", features = ["full"] }
9+
- futures = { version = "0.3" }
10+
- rustls = { version = "0.23.27" }
11+
- futures-rustls = { version = "0.26.0" }
12+
- async-std = { version = "1.13.1" }

rust/ql/test/library-tests/dataflow/sources/test.rs renamed to rust/ql/test/library-tests/dataflow/sources/net/test.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
#![allow(deprecated)]
2-
31
fn sink<T>(_: T) { }
42

53
// --- tests ---
64

5+
use std::io::{Read, Write, BufRead};
6+
use tokio::io::{AsyncReadExt, AsyncWriteExt};
7+
use http_body_util::BodyExt;
8+
use std::net::ToSocketAddrs;
9+
710
async fn test_reqwest() -> Result<(), reqwest::Error> {
811
let remote_string1 = reqwest::blocking::get("example.com")?.text()?; // $ Alert[rust/summary/taint-sources]
912
sink(remote_string1); // $ hasTaintFlow="example.com"
@@ -32,9 +35,6 @@ async fn test_reqwest() -> Result<(), reqwest::Error> {
3235
Ok(())
3336
}
3437

35-
use std::io::Write;
36-
use http_body_util::BodyExt;
37-
3838
async fn test_hyper_http(case: i64) -> Result<(), Box<dyn std::error::Error>> {
3939
// using http + hyper libs to fetch a web page
4040
let address = "example.com:80";
@@ -146,8 +146,6 @@ async fn test_hyper_http(case: i64) -> Result<(), Box<dyn std::error::Error>> {
146146
Ok(())
147147
}
148148

149-
use std::net::ToSocketAddrs;
150-
151149
async fn test_std_tcpstream(case: i64) -> std::io::Result<()> {
152150
// using std::net to fetch a web page
153151
let address = "example.com:80";
@@ -217,8 +215,6 @@ async fn test_std_tcpstream(case: i64) -> std::io::Result<()> {
217215
Ok(())
218216
}
219217

220-
use tokio::io::AsyncWriteExt;
221-
222218
async fn test_tokio_tcpstream(case: i64) -> std::io::Result<()> {
223219
// using tokio::io to fetch a web page
224220
let address = "example.com:80";
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
qltest_cargo_check: true
22
qltest_dependencies:
3-
- reqwest = { version = "0.12.9", features = ["blocking"] }
4-
- hyper = { version = "1.5.2", features = ["full"] }
5-
- hyper-util = { version = "0.1.10", features = ["full"] }
6-
- http-body-util = { version = "0.1.2" }
73
- http = { version = "1.2.0" }
84
- tokio = { version = "1.43.0", features = ["full"] }
95
- futures = { version = "0.3" }
@@ -12,7 +8,5 @@ qltest_dependencies:
128
- actix-web = { version = "4.10.2" }
139
- axum = { version = "0.8.4" }
1410
- serde_json = { version = "1.0.140" }
15-
- rustls = { version = "0.23.27" }
16-
- futures-rustls = { version = "0.26.0" }
1711
- async-std = { version = "1.13.1" }
1812
- warp = { version = "0.4.2", features = ["server"] }

0 commit comments

Comments
 (0)