Skip to content

Commit bc226e2

Browse files
committed
Rust: Add more general test cases for async_std::fs and tokio::fs.
1 parent 5da296d commit bc226e2

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@
7474
| test.rs:607:21:607:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
7575
| test.rs:608:21:608:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
7676
| test.rs:616:21:616:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
77-
| test.rs:648:26:648:53 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
78-
| test.rs:667:26:667:61 | ...::connect_timeout | Flow source 'RemoteSource' of type remote (DEFAULT). |
79-
| test.rs:719:28:719:57 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
80-
| test.rs:801:22:801:49 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
81-
| test.rs:827:22:827:50 | ...::new | Flow source 'RemoteSource' of type remote (DEFAULT). |
82-
| test.rs:854:16:854:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
83-
| test.rs:854:16:854:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
77+
| test.rs:658:26:658:53 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
78+
| test.rs:677:26:677:61 | ...::connect_timeout | Flow source 'RemoteSource' of type remote (DEFAULT). |
79+
| test.rs:729:28:729:57 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
80+
| test.rs:811:22:811:49 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
81+
| test.rs:837:22:837:50 | ...::new | Flow source 'RemoteSource' of type remote (DEFAULT). |
82+
| test.rs:864:16:864:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
83+
| test.rs:864:16:864:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
8484
| test_futures_io.rs:19:15:19:32 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
8585
| web_frameworks.rs:11:31:11:31 | a | Flow source 'RemoteSource' of type remote (DEFAULT). |
8686
| web_frameworks.rs:11:31:11:31 | a | Flow source 'RemoteSource' of type remote (DEFAULT). |

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,16 @@ async fn test_tokio_file() -> std::io::Result<()> {
625625
use async_std::io::ReadExt;
626626

627627
async fn test_async_std_file() -> std::io::Result<()> {
628+
// --- file ---
629+
630+
let mut file = async_std::fs::File::open("file.txt").await?; // $ MISSING: Alert[rust/summary/taint-sources]
631+
632+
{
633+
let mut buffer = [0u8; 100];
634+
let _bytes = file.read(&mut buffer).await?;
635+
sink(&buffer); // $ MISSING: hasTaintFlow="file.txt"
636+
}
637+
628638
// --- OpenOptions ---
629639

630640
{

rust/ql/test/query-tests/security/CWE-022/src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,15 @@ fn sinks(path1: &Path, path2: &Path) {
124124
let _ = std::fs::File::open(path1); // $ path-injection-sink
125125
let _ = std::fs::File::open_buffered(path1); // $ path-injection-sink
126126
let _ = std::fs::OpenOptions::new().open(path1); // $ MISSING: path-injection-sink
127+
128+
let _ = tokio::fs::read(path1); // $ MISSING: path-injection-sink
129+
let _ = tokio::fs::read_to_string(path1); // $ MISSING: path-injection-sink
130+
let _ = tokio::fs::remove_file(path1); // $ MISSING: path-injection-sink
127131
let _ = tokio::fs::OpenOptions::new().open(path1); // $ MISSING: path-injection-sink
132+
133+
let _ = async_std::fs::read(path1); // $ MISSING: path-injection-sink
134+
let _ = async_std::fs::read_to_string(path1); // $ MISSING: path-injection-sink
135+
let _ = async_std::fs::remove_file(path1); // $ MISSING: path-injection-sink
128136
let _ = async_std::fs::OpenOptions::new().open(path1); // $ MISSING: path-injection-sink
129137
}
130138

0 commit comments

Comments
 (0)