Skip to content

Commit 49b4adc

Browse files
committed
Rust: Add more tests for DirEntry, PathBuf, OsString.
1 parent 8da4482 commit 49b4adc

File tree

2 files changed

+59
-27
lines changed

2 files changed

+59
-27
lines changed

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

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,34 @@
5555
| test.rs:413:31:413:38 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
5656
| test.rs:418:22:418:39 | ...::read_to_string | Flow source 'FileSource' of type file (DEFAULT). |
5757
| test.rs:418:22:418:39 | ...::read_to_string | Flow source 'FileSource' of type file (DEFAULT). |
58-
| test.rs:424:22:424:25 | path | Flow source 'FileSource' of type file (DEFAULT). |
59-
| test.rs:425:27:425:35 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
60-
| test.rs:431:22:431:34 | ...::read_link | Flow source 'FileSource' of type file (DEFAULT). |
61-
| test.rs:440:31:440:45 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
62-
| test.rs:445:31:445:45 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
63-
| test.rs:450:22:450:46 | ...::read_to_string | Flow source 'FileSource' of type file (DEFAULT). |
64-
| test.rs:456:26:456:29 | path | Flow source 'FileSource' of type file (DEFAULT). |
65-
| test.rs:456:26:456:29 | path | Flow source 'FileSource' of type file (DEFAULT). |
66-
| test.rs:457:31:457:39 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
67-
| test.rs:457:31:457:39 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
68-
| test.rs:463:22:463:41 | ...::read_link | Flow source 'FileSource' of type file (DEFAULT). |
69-
| test.rs:473:20:473:38 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
70-
| test.rs:530:21:530:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
71-
| test.rs:531:21:531:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
72-
| test.rs:539:21:539:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
73-
| test.rs:551:20:551:40 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
74-
| test.rs:607:21:607:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
75-
| test.rs:608:21:608:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
76-
| test.rs:616:21:616:41 | ...::open | Flow source 'FileSource' of type file (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). |
58+
| test.rs:425:22:425:25 | path | Flow source 'FileSource' of type file (DEFAULT). |
59+
| test.rs:439:27:439:35 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
60+
| test.rs:450:22:450:25 | path | Flow source 'FileSource' of type file (DEFAULT). |
61+
| test.rs:451:27:451:35 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
62+
| test.rs:461:22:461:34 | ...::read_link | Flow source 'FileSource' of type file (DEFAULT). |
63+
| test.rs:470:31:470:45 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
64+
| test.rs:475:31:475:45 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
65+
| test.rs:480:22:480:46 | ...::read_to_string | Flow source 'FileSource' of type file (DEFAULT). |
66+
| test.rs:486:26:486:29 | path | Flow source 'FileSource' of type file (DEFAULT). |
67+
| test.rs:486:26:486:29 | path | Flow source 'FileSource' of type file (DEFAULT). |
68+
| test.rs:487:31:487:39 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
69+
| test.rs:487:31:487:39 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
70+
| test.rs:493:22:493:41 | ...::read_link | Flow source 'FileSource' of type file (DEFAULT). |
71+
| test.rs:503:20:503:38 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
72+
| test.rs:560:21:560:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
73+
| test.rs:561:21:561:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
74+
| test.rs:569:21:569:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
75+
| test.rs:581:20:581:40 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
76+
| test.rs:637:21:637:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
77+
| test.rs:638:21:638:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
78+
| test.rs:646:21:646:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
79+
| test.rs:688:26:688:53 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
80+
| test.rs:707:26:707:61 | ...::connect_timeout | Flow source 'RemoteSource' of type remote (DEFAULT). |
81+
| test.rs:759:28:759:57 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
82+
| test.rs:841:22:841:49 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
83+
| test.rs:867:22:867:50 | ...::new | Flow source 'RemoteSource' of type remote (DEFAULT). |
84+
| test.rs:894:16:894:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
85+
| test.rs:894:16:894:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
8486
| test_futures_io.rs:19:15:19:32 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
8587
| web_frameworks.rs:11:31:11:31 | a | Flow source 'RemoteSource' of type remote (DEFAULT). |
8688
| 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: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,41 @@ fn test_fs() -> Result<(), Box<dyn std::error::Error>> {
421421

422422
for entry in fs::read_dir("directory")? {
423423
let e = entry?;
424+
424425
let path = e.path(); // $ Alert[rust/summary/taint-sources]
425-
let file_name = e.file_name(); // $ Alert[rust/summary/taint-sources]
426+
sink(path.clone()); // $ hasTaintFlow
427+
sink(path.clone().as_path()); // $ hasTaintFlow
428+
sink(path.clone().into_os_string()); // $ MISSING: hasTaintFlow
429+
sink(std::path::PathBuf::from(path.clone().into_boxed_path())); // $ MISSING: hasTaintFlow
430+
sink(path.clone().as_os_str()); // $ MISSING: hasTaintFlow
431+
sink(path.clone().as_mut_os_str()); // $ MISSING: hasTaintFlow
432+
sink(path.to_str()); // $ MISSING: hasTaintFlow
433+
sink(path.to_path_buf()); // $ MISSING: hasTaintFlow
434+
sink(path.file_name().unwrap()); // $ MISSING: hasTaintFlow
435+
sink(path.extension().unwrap()); // $ MISSING: hasTaintFlow
436+
sink(path.canonicalize().unwrap()); // $ MISSING: hasTaintFlow
426437
sink(path); // $ hasTaintFlow
438+
439+
let file_name = e.file_name(); // $ Alert[rust/summary/taint-sources]
440+
sink(file_name.clone()); // $ hasTaintFlow
441+
sink(file_name.clone().into_string().unwrap()); // $ MISSING: hasTaintFlow
442+
sink(file_name.to_str().unwrap()); // $ MISSING: hasTaintFlow
443+
sink(file_name.to_string_lossy().to_mut()); // $ MISSING: hasTaintFlow
444+
sink(file_name.clone().as_encoded_bytes()); // $ MISSING: hasTaintFlow
427445
sink(file_name); // $ hasTaintFlow
428446
}
447+
for entry in std::path::Path::new("directory").read_dir()? {
448+
let e = entry?;
449+
450+
let path = e.path(); // $ Alert[rust/summary/taint-sources]
451+
let file_name = e.file_name(); // $ Alert[rust/summary/taint-sources]
452+
}
453+
for entry in std::path::PathBuf::from("directory").read_dir()? {
454+
let e = entry?;
455+
456+
let path = e.path(); // $ MISSING: Alert[rust/summary/taint-sources]
457+
let file_name = e.file_name(); // $ MISSING: Alert[rust/summary/taint-sources]
458+
}
429459

430460
{
431461
let target = fs::read_link("symlink.txt")?; // $ Alert[rust/summary/taint-sources]

0 commit comments

Comments
 (0)