Skip to content

Commit 258c1af

Browse files
committed
Rust: Add tests for std::fs sources.
1 parent cef3cd9 commit 258c1af

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
| test.rs:80:24:80:35 | ...::get | Flow source 'RemoteSource' of type remote (DEFAULT). |
2323
| test.rs:112:35:112:46 | send_request | Flow source 'RemoteSource' of type remote (DEFAULT). |
2424
| test.rs:119:31:119:42 | send_request | Flow source 'RemoteSource' of type remote (DEFAULT). |
25-
| test.rs:352:16:352:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
25+
| test.rs:386:16:386:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,40 @@ async fn test_hyper_http(case: i64) -> Result<(), Box<dyn std::error::Error>> {
198198
Ok(())
199199
}
200200

201+
use std::fs;
202+
203+
fn test_fs() -> Result<(), Box<dyn std::error::Error>> {
204+
{
205+
let buffer: Vec<u8> = std::fs::read("file.bin")?; // $ MISSING: Alert[rust/summary/taint-sources]
206+
sink(buffer); // $ MISSING: hasTaintFlow
207+
}
208+
209+
{
210+
let buffer: Vec<u8> = fs::read("file.bin")?; // $ MISSING: Alert[rust/summary/taint-sources]
211+
sink(buffer); // $ MISSING: hasTaintFlow
212+
}
213+
214+
{
215+
let buffer = fs::read_to_string("file.txt")?; // $ MISSING: Alert[rust/summary/taint-sources]
216+
sink(buffer); // $ MISSING: hasTaintFlow
217+
}
218+
219+
for entry in fs::read_dir("directory")? {
220+
let e = entry?;
221+
let path = e.path(); // $ MISSING: Alert[rust/summary/taint-sources]
222+
let file_name = e.file_name(); // $ MISSING: Alert[rust/summary/taint-sources]
223+
sink(path); // $ MISSING: hasTaintFlow
224+
sink(file_name); // $ MISSING: hasTaintFlow
225+
}
226+
227+
{
228+
let target = fs::read_link("symlink.txt")?; // $ MISSING: Alert[rust/summary/taint-sources]
229+
sink(target); // $ MISSING: hasTaintFlow
230+
}
231+
232+
Ok(())
233+
}
234+
201235
use std::io::Read;
202236
use std::io::BufRead;
203237

0 commit comments

Comments
 (0)