Skip to content

Commit f4ae211

Browse files
committed
Rust: Add models for tokio (fs).
1 parent 7439b0c commit f4ae211

File tree

4 files changed

+51
-27
lines changed

4 files changed

+51
-27
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/rust-all
4+
extensible: sourceModel
5+
data:
6+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::fs::read::read", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "file", "manual"]
7+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::fs::read_to_string::read_to_string", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "file", "manual"]
8+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::fs::read_link::read_link", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "file", "manual"]
9+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "<crate::fs::read_dir::DirEntry>::path", "ReturnValue", "file", "manual"]
10+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "<crate::fs::read_dir::DirEntry>::file_name", "ReturnValue", "file", "manual"]
11+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "<crate::fs::file::File>::open", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "file", "manual"]

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ extensions:
4646
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_f32_le", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
4747
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_f64", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
4848
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_f64_le", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
49+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::chain", "Argument[self]", "ReturnValue", "taint", "manual"]
50+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::chain", "Argument[0]", "ReturnValue", "taint", "manual"]
51+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::take", "Argument[self]", "ReturnValue", "taint", "manual"]

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,18 @@
5454
| test.rs:423:22:423:25 | path | Flow source 'FileSource' of type file (DEFAULT). |
5555
| test.rs:424:27:424:35 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
5656
| test.rs:430:22:430:34 | ...::read_link | Flow source 'FileSource' of type file (DEFAULT). |
57+
| test.rs:439:31:439:45 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
58+
| test.rs:444:31:444:45 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
59+
| test.rs:449:22:449:46 | ...::read_to_string | Flow source 'FileSource' of type file (DEFAULT). |
60+
| test.rs:455:26:455:29 | path | Flow source 'FileSource' of type file (DEFAULT). |
61+
| test.rs:456:31:456:39 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
62+
| test.rs:462:22:462:41 | ...::read_link | Flow source 'FileSource' of type file (DEFAULT). |
5763
| test.rs:472:20:472:38 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
5864
| test.rs:506:21:506:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
5965
| test.rs:507:21:507:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
6066
| test.rs:515:21:515:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
67+
| test.rs:527:20:527:40 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
68+
| test.rs:574:21:574:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
69+
| test.rs:575:21:575:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
70+
| test.rs:583:21:583:41 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
6171
| test.rs:775:16:775:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -436,31 +436,31 @@ fn test_fs() -> Result<(), Box<dyn std::error::Error>> {
436436

437437
async fn test_tokio_fs() -> Result<(), Box<dyn std::error::Error>> {
438438
{
439-
let buffer: Vec<u8> = tokio::fs::read("file.bin").await?; // $ MISSING: Alert[rust/summary/taint-sources]
440-
sink(buffer); // $ MISSING: hasTaintFlow="file.bin"
439+
let buffer: Vec<u8> = tokio::fs::read("file.bin").await?; // $ Alert[rust/summary/taint-sources]
440+
sink(buffer); // $ hasTaintFlow="file.bin"
441441
}
442442

443443
{
444-
let buffer: Vec<u8> = tokio::fs::read("file.bin").await?; // $ MISSING: Alert[rust/summary/taint-sources]
445-
sink(buffer); // $ MISSING: hasTaintFlow="file.bin"
444+
let buffer: Vec<u8> = tokio::fs::read("file.bin").await?; // $ Alert[rust/summary/taint-sources]
445+
sink(buffer); // $ hasTaintFlow="file.bin"
446446
}
447447

448448
{
449-
let buffer = tokio::fs::read_to_string("file.txt").await?; // $ MISSING: Alert[rust/summary/taint-sources]
450-
sink(buffer); // $ MISSING: hasTaintFlow="file.txt"
449+
let buffer = tokio::fs::read_to_string("file.txt").await?; // $ Alert[rust/summary/taint-sources]
450+
sink(buffer); // $ hasTaintFlow="file.txt"
451451
}
452452

453453
let mut read_dir = tokio::fs::read_dir("directory").await?;
454454
for entry in read_dir.next_entry().await? {
455-
let path = entry.path(); // $ MISSING: Alert[rust/summary/taint-sources]
456-
let file_name = entry.file_name(); // $ MISSING: Alert[rust/summary/taint-sources]
457-
sink(path); // $ MISSING: hasTaintFlow
458-
sink(file_name); // $ MISSING: hasTaintFlow
455+
let path = entry.path(); // $ Alert[rust/summary/taint-sources]
456+
let file_name = entry.file_name(); // $ Alert[rust/summary/taint-sources]
457+
sink(path); // $ hasTaintFlow
458+
sink(file_name); // $ hasTaintFlow
459459
}
460460

461461
{
462-
let target = tokio::fs::read_link("symlink.txt").await?; // $ MISSING: Alert[rust/summary/taint-sources]
463-
sink(target); // $ MISSING: hasTaintFlow="symlink.txt"
462+
let target = tokio::fs::read_link("symlink.txt").await?; // $ Alert[rust/summary/taint-sources]
463+
sink(target); // $ hasTaintFlow="symlink.txt"
464464
}
465465

466466
Ok(())
@@ -524,66 +524,66 @@ fn test_io_file() -> std::io::Result<()> {
524524
async fn test_tokio_file() -> std::io::Result<()> {
525525
// --- file ---
526526

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

529529
{
530530
let mut buffer = [0u8; 100];
531531
let _bytes = file.read(&mut buffer).await?;
532-
sink(&buffer); // $ MISSING: hasTaintFlow="file.txt"
532+
sink(&buffer); // $ hasTaintFlow="file.txt"
533533
}
534534

535535
{
536536
let mut buffer = Vec::<u8>::new();
537537
let _bytes = file.read_to_end(&mut buffer).await?;
538-
sink(&buffer); // $ MISSING: hasTaintFlow="file.txt"
538+
sink(&buffer); // $ hasTaintFlow="file.txt"
539539
}
540540

541541
{
542542
let mut buffer = String::new();
543543
let _bytes = file.read_to_string(&mut buffer).await?;
544-
sink(&buffer); // $ MISSING: hasTaintFlow="file.txt"
544+
sink(&buffer); // $ hasTaintFlow="file.txt"
545545
}
546546

547547
{
548548
let mut buffer = [0; 100];
549549
file.read_exact(&mut buffer).await?;
550-
sink(&buffer); // $ MISSING: hasTaintFlow="file.txt"
550+
sink(&buffer); // $ hasTaintFlow="file.txt"
551551
}
552552

553553
{
554554
let v1 = file.read_u8().await?;
555555
let v2 = file.read_i16().await?;
556556
let v3 = file.read_f32().await?;
557557
let v4 = file.read_i64_le().await?;
558-
sink(v1); // $ MISSING: hasTaintFlow
559-
sink(v2); // $ MISSING: hasTaintFlow
560-
sink(v3); // $ MISSING: hasTaintFlow
561-
sink(v4); // $ MISSING: hasTaintFlow
558+
sink(v1); // $ hasTaintFlow="file.txt"
559+
sink(v2); // $ hasTaintFlow="file.txt"
560+
sink(v3); // $ hasTaintFlow="file.txt"
561+
sink(v4); // $ hasTaintFlow="file.txt"
562562
}
563563

564564
{
565565
let mut buffer = bytes::BytesMut::new();
566566
file.read_buf(&mut buffer).await?;
567-
sink(&buffer); // $ MISSING: hasTaintFlow
567+
sink(&buffer); // $ hasTaintFlow="file.txt"
568568
}
569569

570570
// --- misc operations ---
571571

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

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

589589
Ok(())

0 commit comments

Comments
 (0)