Skip to content

Commit 627496d

Browse files
committed
Rust: Add source tests for tokio (fs).
1 parent b2339ef commit 627496d

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

rust/ql/test/library-tests/dataflow/sources/TaintSources.expected

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
| test.rs:423:22:423:25 | path | Flow source 'FileSource' of type file (DEFAULT). |
4343
| test.rs:424:27:424:35 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
4444
| test.rs:430:22:430:34 | ...::read_link | Flow source 'FileSource' of type file (DEFAULT). |
45-
| test.rs:440:20:440:38 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
46-
| test.rs:474:21:474:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
47-
| test.rs:475:21:475:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
48-
| test.rs:483:21:483:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
49-
| test.rs:743:16:743:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
45+
| test.rs:472:20:472:38 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
46+
| test.rs:506:21:506:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
47+
| test.rs:507:21:507:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
48+
| test.rs:515:21:515:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
49+
| test.rs:775:16:775:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,38 @@ fn test_fs() -> Result<(), Box<dyn std::error::Error>> {
434434
Ok(())
435435
}
436436

437+
async fn test_tokio_fs() -> Result<(), Box<dyn std::error::Error>> {
438+
{
439+
let buffer: Vec<u8> = tokio::fs::read("file.bin").await?; // $ MISSING: Alert[rust/summary/taint-sources]
440+
sink(buffer); // $ MISSING: hasTaintFlow="file.bin"
441+
}
442+
443+
{
444+
let buffer: Vec<u8> = tokio::fs::read("file.bin").await?; // $ MISSING: Alert[rust/summary/taint-sources]
445+
sink(buffer); // $ MISSING: hasTaintFlow="file.bin"
446+
}
447+
448+
{
449+
let buffer = tokio::fs::read_to_string("file.txt").await?; // $ MISSING: Alert[rust/summary/taint-sources]
450+
sink(buffer); // $ MISSING: hasTaintFlow="file.txt"
451+
}
452+
453+
let mut read_dir = tokio::fs::read_dir("directory").await?;
454+
for entry in read_dir.next_entry().await? {
455+
let path = entry.path(); // $ MISSING: Alert[rust/summary/taint-sources]
456+
let file_name = entry.file_name(); // $ MISSING: Alert[rust/summary/taint-sources]
457+
sink(path); // $ MISSING: hasTaintFlow
458+
sink(file_name); // $ MISSING: hasTaintFlow
459+
}
460+
461+
{
462+
let target = tokio::fs::read_link("symlink.txt").await?; // $ MISSING: Alert[rust/summary/taint-sources]
463+
sink(target); // $ MISSING: hasTaintFlow="symlink.txt"
464+
}
465+
466+
Ok(())
467+
}
468+
437469
fn test_io_file() -> std::io::Result<()> {
438470
// --- file ---
439471

@@ -781,6 +813,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
781813
Err(e) => println!("error: {}", e),
782814
}
783815

816+
println!("test_tokio_fs...");
817+
match futures::executor::block_on(test_tokio_fs()) {
818+
Ok(_) => println!("complete"),
819+
Err(e) => println!("error: {}", e),
820+
}
821+
784822
println!("test_io_file...");
785823
match test_io_file() {
786824
Ok(_) => println!("complete"),

0 commit comments

Comments
 (0)