Skip to content

Commit 8b04bc0

Browse files
committed
Rust: Model std::fs::OpenOptions and similar.
1 parent 9fbbe02 commit 8b04bc0

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

rust/ql/lib/codeql/rust/frameworks/asyncstd/fs.model.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ extensions:
99
- ["<async_std::fs::dir_entry::DirEntry>::path", "ReturnValue", "file", "manual"]
1010
- ["<async_std::fs::dir_entry::DirEntry>::file_name", "ReturnValue", "file", "manual"]
1111
- ["<async_std::fs::file::File>::open", "ReturnValue.Future.Field[core::result::Result::Ok(0)]", "file", "manual"]
12+
- ["<async_std::fs::open_options::OpenOptions>::open", "ReturnValue.Future.Field[core::result::Result::Ok(0)]", "file", "manual"]
1213
- addsTo:
1314
pack: codeql/rust-all
1415
extensible: sinkModel
@@ -32,6 +33,7 @@ extensions:
3233
- ["<async_std::fs::dir_builder::DirBuilder>::create", "Argument[0]", "path-injection", "manual"]
3334
- ["<async_std::fs::file::File>::create", "Argument[0]", "path-injection", "manual"]
3435
- ["<async_std::fs::file::File>::open", "Argument[0]", "path-injection", "manual"]
36+
- ["<async_std::fs::open_options::OpenOptions>::open", "Argument[0]", "path-injection", "manual"]
3537
- addsTo:
3638
pack: codeql/rust-all
3739
extensible: summaryModel

rust/ql/lib/codeql/rust/frameworks/stdlib/fs.model.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ extensions:
1010
- ["<std::fs::DirEntry>::file_name", "ReturnValue", "file", "manual"]
1111
- ["<std::fs::File>::open", "ReturnValue.Field[core::result::Result::Ok(0)]", "file", "manual"]
1212
- ["<std::fs::File>::open_buffered", "ReturnValue.Field[core::result::Result::Ok(0)]", "file", "manual"]
13+
- ["<std::fs::OpenOptions>::open", "ReturnValue.Field[core::result::Result::Ok(0)]", "file", "manual"]
1314
- addsTo:
1415
pack: codeql/rust-all
1516
extensible: sinkModel
@@ -37,6 +38,7 @@ extensions:
3738
- ["<std::fs::File>::create_new", "Argument[0]", "path-injection", "manual"]
3839
- ["<std::fs::File>::open", "Argument[0]", "path-injection", "manual"]
3940
- ["<std::fs::File>::open_buffered", "Argument[0]", "path-injection", "manual"]
41+
- ["<std::fs::OpenOptions>::open", "Argument[0]", "path-injection", "manual"]
4042
- addsTo:
4143
pack: codeql/rust-all
4244
extensible: summaryModel

rust/ql/lib/codeql/rust/frameworks/tokio/fs.model.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ extensions:
99
- ["<tokio::fs::read_dir::DirEntry>::path", "ReturnValue", "file", "manual"]
1010
- ["<tokio::fs::read_dir::DirEntry>::file_name", "ReturnValue", "file", "manual"]
1111
- ["<tokio::fs::file::File>::open", "ReturnValue.Future.Field[core::result::Result::Ok(0)]", "file", "manual"]
12+
- ["<tokio::fs::open_options::OpenOptions>::open", "ReturnValue.Future.Field[core::result::Result::Ok(0)]", "file", "manual"]
1213
- addsTo:
1314
pack: codeql/rust-all
1415
extensible: sinkModel
@@ -37,6 +38,7 @@ extensions:
3738
- ["<tokio::fs::file::File>::create", "Argument[0]", "path-injection", "manual"]
3839
- ["<tokio::fs::file::File>::create_new", "Argument[0]", "path-injection", "manual"]
3940
- ["<tokio::fs::file::File>::open", "Argument[0]", "path-injection", "manual"]
41+
- ["<tokio::fs::open_options::OpenOptions>::open", "Argument[0]", "path-injection", "manual"]
4042
- addsTo:
4143
pack: codeql/rust-all
4244
extensible: summaryModel

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,19 @@
6969
| test.rs:487:31:487:39 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
7070
| test.rs:493:22:493:41 | ...::read_link | Flow source 'FileSource' of type file (DEFAULT). |
7171
| test.rs:503:20:503:38 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
72+
| test.rs:536:50:536:53 | open | Flow source 'FileSource' of type file (DEFAULT). |
73+
| test.rs:543:67:543:70 | open | Flow source 'FileSource' of type file (DEFAULT). |
74+
| test.rs:550:101:550:104 | open | Flow source 'FileSource' of type file (DEFAULT). |
7275
| test.rs:560:21:560:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
7376
| test.rs:561:21:561:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
7477
| test.rs:569:21:569:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
7578
| test.rs:581:20:581:40 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
79+
| test.rs:627:52:627:55 | open | Flow source 'FileSource' of type file (DEFAULT). |
7680
| test.rs:637:21:637:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
7781
| test.rs:638:21:638:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
7882
| test.rs:646:21:646:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
7983
| test.rs:660:20:660:44 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
84+
| test.rs:671:56:671:59 | open | Flow source 'FileSource' of type file (DEFAULT). |
8085
| test.rs:688:26:688:53 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
8186
| test.rs:707:26:707:61 | ...::connect_timeout | Flow source 'RemoteSource' of type remote (DEFAULT). |
8287
| test.rs:759:28:759:57 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -533,24 +533,24 @@ fn test_io_file() -> std::io::Result<()> {
533533
// --- OpenOptions ---
534534

535535
{
536-
let mut f1 = std::fs::OpenOptions::new().open("f1.txt").unwrap(); // $ MISSING: Alert[rust/summary/taint-sources]
536+
let mut f1 = std::fs::OpenOptions::new().open("f1.txt").unwrap(); // $ Alert[rust/summary/taint-sources]
537537
let mut buffer = [0u8; 1024];
538538
let _bytes = f1.read(&mut buffer)?;
539-
sink(&buffer); // $ MISSING: hasTaintFlow="f1.txt"
539+
sink(&buffer); // $ hasTaintFlow="f1.txt"
540540
}
541541

542542
{
543-
let mut f2 = std::fs::OpenOptions::new().create_new(true).open("f2.txt").unwrap(); // $ MISSING: Alert[rust/summary/taint-sources]
543+
let mut f2 = std::fs::OpenOptions::new().create_new(true).open("f2.txt").unwrap(); // $ Alert[rust/summary/taint-sources]
544544
let mut buffer = [0u8; 1024];
545545
let _bytes = f2.read(&mut buffer)?;
546-
sink(&buffer); // $ MISSING: hasTaintFlow="f2.txt"
546+
sink(&buffer); // $ hasTaintFlow="f2.txt"
547547
}
548548

549549
{
550-
let mut f3 = std::fs::OpenOptions::new().read(true).write(true).truncate(true).create(true).open("f3.txt").unwrap(); // $ MISSING: Alert[rust/summary/taint-sources]
550+
let mut f3 = std::fs::OpenOptions::new().read(true).write(true).truncate(true).create(true).open("f3.txt").unwrap(); // $ Alert[rust/summary/taint-sources]
551551
let mut buffer = [0u8; 1024];
552552
let _bytes = f3.read(&mut buffer)?;
553-
sink(&buffer); // $ MISSING: hasTaintFlow="f3.txt"
553+
sink(&buffer); // $ hasTaintFlow="f3.txt"
554554
}
555555

556556
// --- misc operations ---
@@ -624,7 +624,7 @@ async fn test_tokio_file() -> std::io::Result<()> {
624624
// --- OpenOptions ---
625625

626626
{
627-
let mut f1 = tokio::fs::OpenOptions::new().open("f1.txt").await?; // $ MISSING: Alert[rust/summary/taint-sources]
627+
let mut f1 = tokio::fs::OpenOptions::new().open("f1.txt").await?; // $ Alert[rust/summary/taint-sources]
628628
let mut buffer = [0u8; 1024];
629629
let _bytes = f1.read(&mut buffer).await?;
630630
sink(&buffer); // $ MISSING: hasTaintFlow="f1.txt"
@@ -668,7 +668,7 @@ async fn test_async_std_file() -> std::io::Result<()> {
668668
// --- OpenOptions ---
669669

670670
{
671-
let mut f1 = async_std::fs::OpenOptions::new().open("f1.txt").await?; // $ MISSING: Alert[rust/summary/taint-sources]
671+
let mut f1 = async_std::fs::OpenOptions::new().open("f1.txt").await?; // $ Alert[rust/summary/taint-sources]
672672
let mut buffer = [0u8; 1024];
673673
let _bytes = f1.read(&mut buffer).await?;
674674
sink(&buffer); // $ MISSING: hasTaintFlow="f1.txt"

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,21 @@ fn sinks(path1: &Path, path2: &Path) {
148148
let _ = std::fs::File::open_buffered(path1); // $ path-injection-sink
149149
let _ = std::fs::DirBuilder::new().create(path1); // $ path-injection-sink
150150
let _ = std::fs::DirBuilder::new().recursive(true).create(path1); // $ path-injection-sink
151-
let _ = std::fs::OpenOptions::new().open(path1); // $ MISSING: path-injection-sink
151+
let _ = std::fs::OpenOptions::new().open(path1); // $ path-injection-sink
152152

153153
let _ = tokio::fs::read(path1); // $ path-injection-sink
154154
let _ = tokio::fs::read_to_string(path1); // $ path-injection-sink
155155
let _ = tokio::fs::remove_file(path1); // $ path-injection-sink
156156
let _ = tokio::fs::DirBuilder::new().create(path1); // $ path-injection-sink
157157
let _ = tokio::fs::DirBuilder::new().recursive(true).create(path1); // $ path-injection-sink
158-
let _ = tokio::fs::OpenOptions::new().open(path1); // $ MISSING: path-injection-sink
158+
let _ = tokio::fs::OpenOptions::new().open(path1); // $ path-injection-sink
159159

160160
let _ = async_std::fs::read(path1); // $ path-injection-sink
161161
let _ = async_std::fs::read_to_string(path1); // $ path-injection-sink
162162
let _ = async_std::fs::remove_file(path1); // $ path-injection-sink
163163
let _ = async_std::fs::DirBuilder::new().create(path1); // $ path-injection-sink
164164
let _ = async_std::fs::DirBuilder::new().recursive(true).create(path1); // $ path-injection-sink
165-
let _ = async_std::fs::OpenOptions::new().open(path1); // $ MISSING: path-injection-sink
165+
let _ = async_std::fs::OpenOptions::new().open(path1); // $ path-injection-sink
166166
}
167167

168168
fn main() {}

0 commit comments

Comments
 (0)