Skip to content

Commit a631130

Browse files
committed
Rust: Split off sources/env test.
1 parent edabfa7 commit a631130

File tree

8 files changed

+292
-63
lines changed

8 files changed

+292
-63
lines changed

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

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
models
2+
| 1 | Source: std::env::args; ReturnValue.Element; commandargs |
3+
| 2 | Source: std::env::args_os; ReturnValue.Element; commandargs |
4+
| 3 | Source: std::env::current_dir; ReturnValue.Field[core::result::Result::Ok(0)]; commandargs |
5+
| 4 | Source: std::env::current_exe; ReturnValue.Field[core::result::Result::Ok(0)]; commandargs |
6+
| 5 | Source: std::env::home_dir; ReturnValue.Field[core::option::Option::Some(0)]; commandargs |
7+
| 6 | Source: std::env::var; ReturnValue.Field[core::result::Result::Ok(0)]; environment |
8+
| 7 | Source: std::env::var_os; ReturnValue.Field[core::option::Option::Some(0)]; environment |
9+
| 8 | Summary: <_ as core::iter::traits::iterator::Iterator>::collect; Argument[self].Element; ReturnValue.Element; value |
10+
| 9 | Summary: <_ as core::iter::traits::iterator::Iterator>::nth; Argument[self].Element; ReturnValue.Field[core::option::Option::Some(0)]; value |
11+
| 10 | Summary: <core::option::Option>::expect; Argument[self].Field[core::option::Option::Some(0)]; ReturnValue; value |
12+
| 11 | Summary: <core::option::Option>::unwrap; Argument[self].Field[core::option::Option::Some(0)]; ReturnValue; value |
13+
| 12 | Summary: <core::result::Result>::expect; Argument[self].Field[core::result::Result::Ok(0)]; ReturnValue; value |
14+
| 13 | Summary: <core::result::Result>::unwrap; Argument[self].Field[core::result::Result::Ok(0)]; ReturnValue; value |
15+
| 14 | Summary: <core::str>::parse; Argument[self]; ReturnValue.Field[core::result::Result::Ok(0)]; taint |
16+
edges
17+
| test.rs:6:10:6:22 | ...::var | test.rs:6:10:6:30 | ...::var(...) | provenance | Src:MaD:6 |
18+
| test.rs:7:10:7:25 | ...::var_os | test.rs:7:10:7:33 | ...::var_os(...) | provenance | Src:MaD:7 |
19+
| test.rs:9:9:9:12 | var1 | test.rs:12:10:12:13 | var1 | provenance | |
20+
| test.rs:9:16:9:28 | ...::var | test.rs:9:16:9:36 | ...::var(...) [Ok] | provenance | Src:MaD:6 |
21+
| test.rs:9:16:9:36 | ...::var(...) [Ok] | test.rs:9:16:9:59 | ... .expect(...) | provenance | MaD:12 |
22+
| test.rs:9:16:9:59 | ... .expect(...) | test.rs:9:9:9:12 | var1 | provenance | |
23+
| test.rs:10:9:10:12 | var2 | test.rs:13:10:13:13 | var2 | provenance | |
24+
| test.rs:10:16:10:31 | ...::var_os | test.rs:10:16:10:39 | ...::var_os(...) [Some] | provenance | Src:MaD:7 |
25+
| test.rs:10:16:10:39 | ...::var_os(...) [Some] | test.rs:10:16:10:48 | ... .unwrap() | provenance | MaD:11 |
26+
| test.rs:10:16:10:48 | ... .unwrap() | test.rs:10:9:10:12 | var2 | provenance | |
27+
| test.rs:27:9:27:12 | args [element] | test.rs:28:20:28:23 | args [element] | provenance | |
28+
| test.rs:27:9:27:12 | args [element] | test.rs:29:17:29:20 | args [element] | provenance | |
29+
| test.rs:27:29:27:42 | ...::args | test.rs:27:29:27:44 | ...::args(...) [element] | provenance | Src:MaD:1 |
30+
| test.rs:27:29:27:44 | ...::args(...) [element] | test.rs:27:29:27:54 | ... .collect() [element] | provenance | MaD:8 |
31+
| test.rs:27:29:27:54 | ... .collect() [element] | test.rs:27:9:27:12 | args [element] | provenance | |
32+
| test.rs:28:9:28:15 | my_path [&ref] | test.rs:34:10:34:16 | my_path | provenance | |
33+
| test.rs:28:19:28:26 | &... [&ref] | test.rs:28:9:28:15 | my_path [&ref] | provenance | |
34+
| test.rs:28:20:28:23 | args [element] | test.rs:28:20:28:26 | args[0] | provenance | |
35+
| test.rs:28:20:28:26 | args[0] | test.rs:28:19:28:26 | &... [&ref] | provenance | |
36+
| test.rs:29:9:29:12 | arg1 [&ref] | test.rs:35:10:35:13 | arg1 | provenance | |
37+
| test.rs:29:16:29:23 | &... [&ref] | test.rs:29:9:29:12 | arg1 [&ref] | provenance | |
38+
| test.rs:29:17:29:20 | args [element] | test.rs:29:17:29:23 | args[1] | provenance | |
39+
| test.rs:29:17:29:23 | args[1] | test.rs:29:16:29:23 | &... [&ref] | provenance | |
40+
| test.rs:30:9:30:12 | arg2 | test.rs:36:10:36:13 | arg2 | provenance | |
41+
| test.rs:30:16:30:29 | ...::args | test.rs:30:16:30:31 | ...::args(...) [element] | provenance | Src:MaD:1 |
42+
| test.rs:30:16:30:31 | ...::args(...) [element] | test.rs:30:16:30:38 | ... .nth(...) [Some] | provenance | MaD:9 |
43+
| test.rs:30:16:30:38 | ... .nth(...) [Some] | test.rs:30:16:30:47 | ... .unwrap() | provenance | MaD:11 |
44+
| test.rs:30:16:30:47 | ... .unwrap() | test.rs:30:9:30:12 | arg2 | provenance | |
45+
| test.rs:31:9:31:12 | arg3 | test.rs:37:10:37:13 | arg3 | provenance | |
46+
| test.rs:31:16:31:32 | ...::args_os | test.rs:31:16:31:34 | ...::args_os(...) [element] | provenance | Src:MaD:2 |
47+
| test.rs:31:16:31:34 | ...::args_os(...) [element] | test.rs:31:16:31:41 | ... .nth(...) [Some] | provenance | MaD:9 |
48+
| test.rs:31:16:31:41 | ... .nth(...) [Some] | test.rs:31:16:31:50 | ... .unwrap() | provenance | MaD:11 |
49+
| test.rs:31:16:31:50 | ... .unwrap() | test.rs:31:9:31:12 | arg3 | provenance | |
50+
| test.rs:32:9:32:12 | arg4 | test.rs:38:10:38:13 | arg4 | provenance | |
51+
| test.rs:32:16:32:29 | ...::args | test.rs:32:16:32:31 | ...::args(...) [element] | provenance | Src:MaD:1 |
52+
| test.rs:32:16:32:31 | ...::args(...) [element] | test.rs:32:16:32:38 | ... .nth(...) [Some] | provenance | MaD:9 |
53+
| test.rs:32:16:32:38 | ... .nth(...) [Some] | test.rs:32:16:32:47 | ... .unwrap() | provenance | MaD:11 |
54+
| test.rs:32:16:32:47 | ... .unwrap() | test.rs:32:16:32:64 | ... .parse() [Ok] | provenance | MaD:14 |
55+
| test.rs:32:16:32:64 | ... .parse() [Ok] | test.rs:32:16:32:73 | ... .unwrap() | provenance | MaD:13 |
56+
| test.rs:32:16:32:73 | ... .unwrap() | test.rs:32:9:32:12 | arg4 | provenance | |
57+
| test.rs:40:9:40:11 | arg | test.rs:41:14:41:16 | arg | provenance | |
58+
| test.rs:40:16:40:29 | ...::args | test.rs:40:16:40:31 | ...::args(...) [element] | provenance | Src:MaD:1 |
59+
| test.rs:40:16:40:31 | ...::args(...) [element] | test.rs:40:9:40:11 | arg | provenance | |
60+
| test.rs:44:9:44:11 | arg | test.rs:45:14:45:16 | arg | provenance | |
61+
| test.rs:44:16:44:32 | ...::args_os | test.rs:44:16:44:34 | ...::args_os(...) [element] | provenance | Src:MaD:2 |
62+
| test.rs:44:16:44:34 | ...::args_os(...) [element] | test.rs:44:9:44:11 | arg | provenance | |
63+
| test.rs:50:9:50:11 | dir | test.rs:54:10:54:12 | dir | provenance | |
64+
| test.rs:50:15:50:35 | ...::current_dir | test.rs:50:15:50:37 | ...::current_dir(...) [Ok] | provenance | Src:MaD:3 |
65+
| test.rs:50:15:50:37 | ...::current_dir(...) [Ok] | test.rs:50:15:50:54 | ... .expect(...) | provenance | MaD:12 |
66+
| test.rs:50:15:50:54 | ... .expect(...) | test.rs:50:9:50:11 | dir | provenance | |
67+
| test.rs:51:9:51:11 | exe | test.rs:55:10:55:12 | exe | provenance | |
68+
| test.rs:51:15:51:35 | ...::current_exe | test.rs:51:15:51:37 | ...::current_exe(...) [Ok] | provenance | Src:MaD:4 |
69+
| test.rs:51:15:51:37 | ...::current_exe(...) [Ok] | test.rs:51:15:51:54 | ... .expect(...) | provenance | MaD:12 |
70+
| test.rs:51:15:51:54 | ... .expect(...) | test.rs:51:9:51:11 | exe | provenance | |
71+
| test.rs:52:9:52:12 | home | test.rs:56:10:56:13 | home | provenance | |
72+
| test.rs:52:16:52:33 | ...::home_dir | test.rs:52:16:52:35 | ...::home_dir(...) [Some] | provenance | Src:MaD:5 |
73+
| test.rs:52:16:52:35 | ...::home_dir(...) [Some] | test.rs:52:16:52:52 | ... .expect(...) | provenance | MaD:10 |
74+
| test.rs:52:16:52:52 | ... .expect(...) | test.rs:52:9:52:12 | home | provenance | |
75+
nodes
76+
| test.rs:6:10:6:22 | ...::var | semmle.label | ...::var |
77+
| test.rs:6:10:6:30 | ...::var(...) | semmle.label | ...::var(...) |
78+
| test.rs:7:10:7:25 | ...::var_os | semmle.label | ...::var_os |
79+
| test.rs:7:10:7:33 | ...::var_os(...) | semmle.label | ...::var_os(...) |
80+
| test.rs:9:9:9:12 | var1 | semmle.label | var1 |
81+
| test.rs:9:16:9:28 | ...::var | semmle.label | ...::var |
82+
| test.rs:9:16:9:36 | ...::var(...) [Ok] | semmle.label | ...::var(...) [Ok] |
83+
| test.rs:9:16:9:59 | ... .expect(...) | semmle.label | ... .expect(...) |
84+
| test.rs:10:9:10:12 | var2 | semmle.label | var2 |
85+
| test.rs:10:16:10:31 | ...::var_os | semmle.label | ...::var_os |
86+
| test.rs:10:16:10:39 | ...::var_os(...) [Some] | semmle.label | ...::var_os(...) [Some] |
87+
| test.rs:10:16:10:48 | ... .unwrap() | semmle.label | ... .unwrap() |
88+
| test.rs:12:10:12:13 | var1 | semmle.label | var1 |
89+
| test.rs:13:10:13:13 | var2 | semmle.label | var2 |
90+
| test.rs:27:9:27:12 | args [element] | semmle.label | args [element] |
91+
| test.rs:27:29:27:42 | ...::args | semmle.label | ...::args |
92+
| test.rs:27:29:27:44 | ...::args(...) [element] | semmle.label | ...::args(...) [element] |
93+
| test.rs:27:29:27:54 | ... .collect() [element] | semmle.label | ... .collect() [element] |
94+
| test.rs:28:9:28:15 | my_path [&ref] | semmle.label | my_path [&ref] |
95+
| test.rs:28:19:28:26 | &... [&ref] | semmle.label | &... [&ref] |
96+
| test.rs:28:20:28:23 | args [element] | semmle.label | args [element] |
97+
| test.rs:28:20:28:26 | args[0] | semmle.label | args[0] |
98+
| test.rs:29:9:29:12 | arg1 [&ref] | semmle.label | arg1 [&ref] |
99+
| test.rs:29:16:29:23 | &... [&ref] | semmle.label | &... [&ref] |
100+
| test.rs:29:17:29:20 | args [element] | semmle.label | args [element] |
101+
| test.rs:29:17:29:23 | args[1] | semmle.label | args[1] |
102+
| test.rs:30:9:30:12 | arg2 | semmle.label | arg2 |
103+
| test.rs:30:16:30:29 | ...::args | semmle.label | ...::args |
104+
| test.rs:30:16:30:31 | ...::args(...) [element] | semmle.label | ...::args(...) [element] |
105+
| test.rs:30:16:30:38 | ... .nth(...) [Some] | semmle.label | ... .nth(...) [Some] |
106+
| test.rs:30:16:30:47 | ... .unwrap() | semmle.label | ... .unwrap() |
107+
| test.rs:31:9:31:12 | arg3 | semmle.label | arg3 |
108+
| test.rs:31:16:31:32 | ...::args_os | semmle.label | ...::args_os |
109+
| test.rs:31:16:31:34 | ...::args_os(...) [element] | semmle.label | ...::args_os(...) [element] |
110+
| test.rs:31:16:31:41 | ... .nth(...) [Some] | semmle.label | ... .nth(...) [Some] |
111+
| test.rs:31:16:31:50 | ... .unwrap() | semmle.label | ... .unwrap() |
112+
| test.rs:32:9:32:12 | arg4 | semmle.label | arg4 |
113+
| test.rs:32:16:32:29 | ...::args | semmle.label | ...::args |
114+
| test.rs:32:16:32:31 | ...::args(...) [element] | semmle.label | ...::args(...) [element] |
115+
| test.rs:32:16:32:38 | ... .nth(...) [Some] | semmle.label | ... .nth(...) [Some] |
116+
| test.rs:32:16:32:47 | ... .unwrap() | semmle.label | ... .unwrap() |
117+
| test.rs:32:16:32:64 | ... .parse() [Ok] | semmle.label | ... .parse() [Ok] |
118+
| test.rs:32:16:32:73 | ... .unwrap() | semmle.label | ... .unwrap() |
119+
| test.rs:34:10:34:16 | my_path | semmle.label | my_path |
120+
| test.rs:35:10:35:13 | arg1 | semmle.label | arg1 |
121+
| test.rs:36:10:36:13 | arg2 | semmle.label | arg2 |
122+
| test.rs:37:10:37:13 | arg3 | semmle.label | arg3 |
123+
| test.rs:38:10:38:13 | arg4 | semmle.label | arg4 |
124+
| test.rs:40:9:40:11 | arg | semmle.label | arg |
125+
| test.rs:40:16:40:29 | ...::args | semmle.label | ...::args |
126+
| test.rs:40:16:40:31 | ...::args(...) [element] | semmle.label | ...::args(...) [element] |
127+
| test.rs:41:14:41:16 | arg | semmle.label | arg |
128+
| test.rs:44:9:44:11 | arg | semmle.label | arg |
129+
| test.rs:44:16:44:32 | ...::args_os | semmle.label | ...::args_os |
130+
| test.rs:44:16:44:34 | ...::args_os(...) [element] | semmle.label | ...::args_os(...) [element] |
131+
| test.rs:45:14:45:16 | arg | semmle.label | arg |
132+
| test.rs:50:9:50:11 | dir | semmle.label | dir |
133+
| test.rs:50:15:50:35 | ...::current_dir | semmle.label | ...::current_dir |
134+
| test.rs:50:15:50:37 | ...::current_dir(...) [Ok] | semmle.label | ...::current_dir(...) [Ok] |
135+
| test.rs:50:15:50:54 | ... .expect(...) | semmle.label | ... .expect(...) |
136+
| test.rs:51:9:51:11 | exe | semmle.label | exe |
137+
| test.rs:51:15:51:35 | ...::current_exe | semmle.label | ...::current_exe |
138+
| test.rs:51:15:51:37 | ...::current_exe(...) [Ok] | semmle.label | ...::current_exe(...) [Ok] |
139+
| test.rs:51:15:51:54 | ... .expect(...) | semmle.label | ... .expect(...) |
140+
| test.rs:52:9:52:12 | home | semmle.label | home |
141+
| test.rs:52:16:52:33 | ...::home_dir | semmle.label | ...::home_dir |
142+
| test.rs:52:16:52:35 | ...::home_dir(...) [Some] | semmle.label | ...::home_dir(...) [Some] |
143+
| test.rs:52:16:52:52 | ... .expect(...) | semmle.label | ... .expect(...) |
144+
| test.rs:54:10:54:12 | dir | semmle.label | dir |
145+
| test.rs:55:10:55:12 | exe | semmle.label | exe |
146+
| test.rs:56:10:56:13 | home | semmle.label | home |
147+
subpaths
148+
testFailures
149+
#select
150+
| test.rs:6:10:6:30 | ...::var(...) | test.rs:6:10:6:22 | ...::var | test.rs:6:10:6:30 | ...::var(...) | $@ | test.rs:6:10:6:22 | ...::var | ...::var |
151+
| test.rs:7:10:7:33 | ...::var_os(...) | test.rs:7:10:7:25 | ...::var_os | test.rs:7:10:7:33 | ...::var_os(...) | $@ | test.rs:7:10:7:25 | ...::var_os | ...::var_os |
152+
| test.rs:12:10:12:13 | var1 | test.rs:9:16:9:28 | ...::var | test.rs:12:10:12:13 | var1 | $@ | test.rs:9:16:9:28 | ...::var | ...::var |
153+
| test.rs:13:10:13:13 | var2 | test.rs:10:16:10:31 | ...::var_os | test.rs:13:10:13:13 | var2 | $@ | test.rs:10:16:10:31 | ...::var_os | ...::var_os |
154+
| test.rs:34:10:34:16 | my_path | test.rs:27:29:27:42 | ...::args | test.rs:34:10:34:16 | my_path | $@ | test.rs:27:29:27:42 | ...::args | ...::args |
155+
| test.rs:35:10:35:13 | arg1 | test.rs:27:29:27:42 | ...::args | test.rs:35:10:35:13 | arg1 | $@ | test.rs:27:29:27:42 | ...::args | ...::args |
156+
| test.rs:36:10:36:13 | arg2 | test.rs:30:16:30:29 | ...::args | test.rs:36:10:36:13 | arg2 | $@ | test.rs:30:16:30:29 | ...::args | ...::args |
157+
| test.rs:37:10:37:13 | arg3 | test.rs:31:16:31:32 | ...::args_os | test.rs:37:10:37:13 | arg3 | $@ | test.rs:31:16:31:32 | ...::args_os | ...::args_os |
158+
| test.rs:38:10:38:13 | arg4 | test.rs:32:16:32:29 | ...::args | test.rs:38:10:38:13 | arg4 | $@ | test.rs:32:16:32:29 | ...::args | ...::args |
159+
| test.rs:41:14:41:16 | arg | test.rs:40:16:40:29 | ...::args | test.rs:41:14:41:16 | arg | $@ | test.rs:40:16:40:29 | ...::args | ...::args |
160+
| test.rs:45:14:45:16 | arg | test.rs:44:16:44:32 | ...::args_os | test.rs:45:14:45:16 | arg | $@ | test.rs:44:16:44:32 | ...::args_os | ...::args_os |
161+
| test.rs:54:10:54:12 | dir | test.rs:50:15:50:35 | ...::current_dir | test.rs:54:10:54:12 | dir | $@ | test.rs:50:15:50:35 | ...::current_dir | ...::current_dir |
162+
| test.rs:55:10:55:12 | exe | test.rs:51:15:51:35 | ...::current_exe | test.rs:55:10:55:12 | exe | $@ | test.rs:51:15:51:35 | ...::current_exe | ...::current_exe |
163+
| test.rs:56:10:56:13 | home | test.rs:52:16:52:33 | ...::home_dir | test.rs:56:10:56:13 | home | $@ | test.rs:52:16:52:33 | ...::home_dir | ...::home_dir |
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
| test.rs:6:10:6:22 | ...::var | Flow source 'EnvironmentSource' of type environment (DEFAULT). |
2+
| test.rs:7:10:7:25 | ...::var_os | Flow source 'EnvironmentSource' of type environment (DEFAULT). |
3+
| test.rs:9:16:9:28 | ...::var | Flow source 'EnvironmentSource' of type environment (DEFAULT). |
4+
| test.rs:10:16:10:31 | ...::var_os | Flow source 'EnvironmentSource' of type environment (DEFAULT). |
5+
| test.rs:15:25:15:38 | ...::vars | Flow source 'EnvironmentSource' of type environment (DEFAULT). |
6+
| test.rs:20:25:20:41 | ...::vars_os | Flow source 'EnvironmentSource' of type environment (DEFAULT). |
7+
| test.rs:27:29:27:42 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
8+
| test.rs:30:16:30:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
9+
| test.rs:31:16:31:32 | ...::args_os | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
10+
| test.rs:32:16:32:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
11+
| test.rs:40:16:40:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
12+
| test.rs:44:16:44:32 | ...::args_os | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
13+
| test.rs:50:15:50:35 | ...::current_dir | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
14+
| test.rs:51:15:51:35 | ...::current_exe | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
15+
| test.rs:52:16:52:33 | ...::home_dir | 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
qltest_cargo_check: true
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
fn sink<T>(_: T) { }
2+
3+
// --- tests ---
4+
5+
fn test_env_vars() {
6+
sink(std::env::var("HOME")); // $ Alert[rust/summary/taint-sources] hasTaintFlow="HOME"
7+
sink(std::env::var_os("PATH")); // $ Alert[rust/summary/taint-sources] hasTaintFlow="PATH"
8+
9+
let var1 = std::env::var("HOME").expect("HOME not set"); // $ Alert[rust/summary/taint-sources]
10+
let var2 = std::env::var_os("PATH").unwrap(); // $ Alert[rust/summary/taint-sources]
11+
12+
sink(var1); // $ hasTaintFlow="HOME"
13+
sink(var2); // $ hasTaintFlow="PATH"
14+
15+
for (key, value) in std::env::vars() { // $ Alert[rust/summary/taint-sources]
16+
sink(key); // $ MISSING: hasTaintFlow
17+
sink(value); // $ MISSING: hasTaintFlow
18+
}
19+
20+
for (key, value) in std::env::vars_os() { // $ Alert[rust/summary/taint-sources]
21+
sink(key); // $ MISSING: hasTaintFlow
22+
sink(value); // $ MISSING: hasTaintFlow
23+
}
24+
}
25+
26+
fn test_env_args() {
27+
let args: Vec<String> = std::env::args().collect(); // $ Alert[rust/summary/taint-sources]
28+
let my_path = &args[0];
29+
let arg1 = &args[1];
30+
let arg2 = std::env::args().nth(2).unwrap(); // $ Alert[rust/summary/taint-sources]
31+
let arg3 = std::env::args_os().nth(3).unwrap(); // $ Alert[rust/summary/taint-sources]
32+
let arg4 = std::env::args().nth(4).unwrap().parse::<usize>().unwrap(); // $ Alert[rust/summary/taint-sources]
33+
34+
sink(my_path); // $ hasTaintFlow
35+
sink(arg1); // $ hasTaintFlow
36+
sink(arg2); // $ hasTaintFlow
37+
sink(arg3); // $ hasTaintFlow
38+
sink(arg4); // $ hasTaintFlow
39+
40+
for arg in std::env::args() { // $ Alert[rust/summary/taint-sources]
41+
sink(arg); // $ hasTaintFlow
42+
}
43+
44+
for arg in std::env::args_os() { // $ Alert[rust/summary/taint-sources]
45+
sink(arg); // $ hasTaintFlow
46+
}
47+
}
48+
49+
fn test_env_dirs() {
50+
let dir = std::env::current_dir().expect("FAILED"); // $ Alert[rust/summary/taint-sources]
51+
let exe = std::env::current_exe().expect("FAILED"); // $ Alert[rust/summary/taint-sources]
52+
let home = std::env::home_dir().expect("FAILED"); // $ Alert[rust/summary/taint-sources]
53+
54+
sink(dir); // $ hasTaintFlow
55+
sink(exe); // $ hasTaintFlow
56+
sink(home); // $ hasTaintFlow
57+
}
58+
59+
async fn main() -> () {
60+
println!("test_env_vars...");
61+
test_env_vars();
62+
63+
println!("test_env_args...");
64+
test_env_args();
65+
66+
println!("test_env_dirs...");
67+
test_env_dirs();
68+
}

0 commit comments

Comments
 (0)