Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Rust: Model std::net and tokio fs, io, net #19446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rust: Add source tests for tokio (file).
  • Loading branch information
geoffw0 committed Apr 24, 2025
commit 809dd20f9d3772c420a16ab18fddb25893b76e2e
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@
| test.rs:451:21:451:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:452:21:452:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:460:21:460:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
| test.rs:471:16:471:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
| test.rs:522:16:522:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
57 changes: 57 additions & 0 deletions 57 rust/ql/test/library-tests/dataflow/sources/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,57 @@ fn test_io_file() -> std::io::Result<()> {
Ok(())
}

async fn test_tokio_file() -> std::io::Result<()> {
// --- file ---

let mut file = tokio::fs::File::open("file.txt").await?; // $ MISSING: Alert[rust/summary/taint-sources]

{
let mut buffer = [0u8; 100];
let _bytes = file.read(&mut buffer).await?;
sink(&buffer); // $ MISSING: hasTaintFlow="file.txt"
}

{
let mut buffer = Vec::<u8>::new();
let _bytes = file.read_to_end(&mut buffer).await?;
sink(&buffer); // $ MISSING: hasTaintFlow="file.txt"
}

{
let mut buffer = String::new();
let _bytes = file.read_to_string(&mut buffer).await?;
sink(&buffer); // $ MISSING: hasTaintFlow="file.txt"
}

{
let mut buffer = [0; 100];
file.read_exact(&mut buffer).await?;
sink(&buffer); // $ MISSING: hasTaintFlow="file.txt"
}

// --- misc operations ---

{
let mut buffer = String::new();
let file1 = tokio::fs::File::open("file.txt").await?; // $ MISSING: Alert[rust/summary/taint-sources]
let file2 = tokio::fs::File::open("another_file.txt").await?; // $ MISSING: [rust/summary/taint-sources]
let mut reader = file1.chain(file2);
reader.read_to_string(&mut buffer).await?;
sink(&buffer); // $ MISSING: hasTaintFlow="file.txt" hasTaintFlow="another_file.txt"
}

{
let mut buffer = String::new();
let file1 = tokio::fs::File::open("file.txt").await?; // $ MISSING: Alert[rust/summary/taint-sources]
let mut reader = file1.take(100);
reader.read_to_string(&mut buffer).await?;
sink(&buffer); // $ MISSING: hasTaintFlow="file.txt"
}

Ok(())
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let case = std::env::args().nth(1).unwrap_or(String::from("1")).parse::<i64>().unwrap(); // $ Alert[rust/summary/taint-sources]
Expand Down Expand Up @@ -515,5 +566,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Err(e) => println!("error: {}", e),
}

println!("test_tokio_file...");
match futures::executor::block_on(test_tokio_file()) {
Ok(_) => println!("complete"),
Err(e) => println!("error: {}", e),
}

Ok(())
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.