Skip to content

Commit 97f7dcb

Browse files
committed
Rust: Add dataflow test cases for neutral models.
1 parent 7e674f3 commit 97f7dcb

File tree

3 files changed

+191
-91
lines changed

3 files changed

+191
-91
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,37 @@ fn test_trait_model<T: Ord>(x: T) {
410410
sink(x7);
411411
}
412412

413+
pub fn generated_source(i: i64) -> i64 {
414+
0
415+
}
416+
417+
pub fn neutral_generated_source(i: i64) -> i64 {
418+
0
419+
}
420+
421+
pub fn neutral_manual_source(i: i64) -> i64 {
422+
0
423+
}
424+
425+
pub fn generated_sink(i: i64) {}
426+
427+
pub fn neutral_generated_sink(i: i64) {}
428+
429+
pub fn neutral_manual_sink(i: i64) {}
430+
431+
fn test_neutrals() {
432+
// neutral models should cause corresponding generated models to be ignored.
433+
// Thus, the `neutral_generated_*` source/sink, which have both a
434+
// generated and a neutral model, should not have flow.
435+
436+
sink(generated_source(1)); // $ hasValueFlow=1
437+
sink(neutral_generated_source(2)); // $ SPURIOUS: hasValueFlow=2
438+
sink(neutral_manual_source(3)); // $ hasValueFlow=3
439+
generated_sink(source(4)); // $ hasValueFlow=4
440+
neutral_generated_sink(source(5)); // $ SPURIOUS: hasValueFlow=5
441+
neutral_manual_sink(source(6)); // $ hasValueFlow=6
442+
}
443+
413444
#[tokio::main]
414445
async fn main() {
415446
test_identify();
@@ -431,5 +462,6 @@ async fn main() {
431462
test_simple_sink();
432463
test_get_async_number().await;
433464
test_arg_source();
465+
test_neutrals();
434466
let dummy = Some(0); // ensure that the the `lang:core` crate is extracted
435467
}

0 commit comments

Comments
 (0)