-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rust: Add additional data flow tests
- Loading branch information
Showing
6 changed files
with
132 additions
and
99 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
rust/ql/test/library-tests/dataflow/closures/inline-flow.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
models | ||
edges | ||
| main.rs:11:20:11:52 | if cond {...} else {...} | main.rs:12:10:12:16 | f(...) | provenance | | | ||
| main.rs:11:30:11:39 | source(...) | main.rs:11:20:11:52 | if cond {...} else {...} | provenance | | | ||
| main.rs:16:20:16:23 | ... | main.rs:18:18:18:21 | data | provenance | | | ||
| main.rs:22:13:22:22 | source(...) | main.rs:23:13:23:13 | a | provenance | | | ||
| main.rs:23:13:23:13 | a | main.rs:16:20:16:23 | ... | provenance | | | ||
| main.rs:27:20:27:23 | ... | main.rs:28:9:32:9 | if cond {...} else {...} | provenance | | | ||
| main.rs:33:13:33:22 | source(...) | main.rs:34:21:34:21 | a | provenance | | | ||
| main.rs:34:13:34:22 | f(...) | main.rs:35:10:35:10 | b | provenance | | | ||
| main.rs:34:21:34:21 | a | main.rs:27:20:27:23 | ... | provenance | | | ||
| main.rs:34:21:34:21 | a | main.rs:34:13:34:22 | f(...) | provenance | | | ||
nodes | ||
| main.rs:11:20:11:52 | if cond {...} else {...} | semmle.label | if cond {...} else {...} | | ||
| main.rs:11:30:11:39 | source(...) | semmle.label | source(...) | | ||
| main.rs:12:10:12:16 | f(...) | semmle.label | f(...) | | ||
| main.rs:16:20:16:23 | ... | semmle.label | ... | | ||
| main.rs:18:18:18:21 | data | semmle.label | data | | ||
| main.rs:22:13:22:22 | source(...) | semmle.label | source(...) | | ||
| main.rs:23:13:23:13 | a | semmle.label | a | | ||
| main.rs:27:20:27:23 | ... | semmle.label | ... | | ||
| main.rs:28:9:32:9 | if cond {...} else {...} | semmle.label | if cond {...} else {...} | | ||
| main.rs:33:13:33:22 | source(...) | semmle.label | source(...) | | ||
| main.rs:34:13:34:22 | f(...) | semmle.label | f(...) | | ||
| main.rs:34:21:34:21 | a | semmle.label | a | | ||
| main.rs:35:10:35:10 | b | semmle.label | b | | ||
subpaths | ||
| main.rs:34:21:34:21 | a | main.rs:27:20:27:23 | ... | main.rs:28:9:32:9 | if cond {...} else {...} | main.rs:34:13:34:22 | f(...) | | ||
testFailures | ||
#select | ||
| main.rs:12:10:12:16 | f(...) | main.rs:11:30:11:39 | source(...) | main.rs:12:10:12:16 | f(...) | $@ | main.rs:11:30:11:39 | source(...) | source(...) | | ||
| main.rs:18:18:18:21 | data | main.rs:22:13:22:22 | source(...) | main.rs:18:18:18:21 | data | $@ | main.rs:22:13:22:22 | source(...) | source(...) | | ||
| main.rs:35:10:35:10 | b | main.rs:33:13:33:22 | source(...) | main.rs:35:10:35:10 | b | $@ | main.rs:33:13:33:22 | source(...) | source(...) | |
12 changes: 12 additions & 0 deletions
12
rust/ql/test/library-tests/dataflow/closures/inline-flow.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* @kind path-problem | ||
*/ | ||
|
||
import rust | ||
import utils.InlineFlowTest | ||
import DefaultFlowTest | ||
import ValueFlow::PathGraph | ||
|
||
from ValueFlow::PathNode source, ValueFlow::PathNode sink | ||
where ValueFlow::flowPath(source, sink) | ||
select sink, source, sink, "$@", source, source.toString() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
fn source(i: i64) -> i64 { | ||
1000 + i | ||
} | ||
|
||
fn sink(s: i64) { | ||
println!("{}", s); | ||
} | ||
|
||
|
||
fn closure_flow_out() { | ||
let f = |cond| if cond { source(92) } else { 0 }; | ||
sink(f(true)); // $ hasValueFlow=92 | ||
} | ||
|
||
fn closure_flow_in() { | ||
let f = |cond, data| | ||
if cond { | ||
sink(data); // $ hasValueFlow=87 | ||
} else { | ||
sink(0) | ||
}; | ||
let a = source(87); | ||
f(true, a); | ||
} | ||
|
||
fn closure_flow_through() { | ||
let f = |cond, data| | ||
if cond { | ||
data | ||
} else { | ||
0 | ||
}; | ||
let a = source(43); | ||
let b = f(true, a); | ||
sink(b); // $ hasValueFlow=43 | ||
} | ||
|
||
fn closure_captured_variable() { | ||
let mut capt = 1; | ||
sink(capt); | ||
let mut f = || { | ||
capt = source(73); | ||
}; | ||
f(); | ||
sink(capt); // $ MISSING: hasValueFlow=73 | ||
let g = || { | ||
sink(capt); // $ MISSING: hasValueFlow=73 | ||
}; | ||
g(); | ||
} | ||
|
||
fn main() { | ||
closure_flow_out(); | ||
closure_flow_in(); | ||
closure_flow_through(); | ||
closure_captured_variable(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters