Skip to content

Commit a5e1702

Browse files
committed
Rust: Add tests for sources involving regular rustls as well.
1 parent 544af7f commit a5e1702

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
| test.rs:619:26:619:61 | ...::connect_timeout | Flow source 'RemoteSource' of type remote (DEFAULT). |
7676
| test.rs:671:28:671:57 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
7777
| test.rs:753:22:753:49 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
78-
| test.rs:775:16:775:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
79-
| test.rs:775:16:775:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
78+
| test.rs:806:16:806:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
79+
| test.rs:806:16:806:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
8080
| web_frameworks.rs:12:31:12:31 | a | Flow source 'RemoteSource' of type remote (DEFAULT). |
8181
| web_frameworks.rs:12:31:12:31 | a | Flow source 'RemoteSource' of type remote (DEFAULT). |
8282
| web_frameworks.rs:21:31:21:35 | TuplePat | Flow source 'RemoteSource' of type remote (DEFAULT). |

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,37 @@ async fn test_std_to_tokio_tcpstream() -> std::io::Result<()> {
770770
Ok(())
771771
}
772772

773+
fn test_rustls() -> std::io::Result<()> {
774+
let config = rustls::ClientConfig::builder()
775+
.with_root_certificates(rustls::RootCertStore::empty())
776+
.with_no_client_auth();
777+
let server_name = rustls::pki_types::ServerName::try_from("www.example.com").unwrap();
778+
let config_arc = std::sync::Arc::new(config);
779+
let mut client = rustls::ClientConnection::new(config_arc, server_name).unwrap(); // $ MISSING: Alert[rust/summary/taint-sources]
780+
let mut reader = client.reader();
781+
sink(&reader); // $ MISSING: hasTaintFlow
782+
783+
{
784+
let mut buffer = [0u8; 100];
785+
let _bytes = reader.read(&mut buffer)?;
786+
sink(&buffer); // $ MISSING: hasTaintFlow
787+
}
788+
789+
{
790+
let mut buffer = Vec::<u8>::new();
791+
let _bytes = reader.read_to_end(&mut buffer)?;
792+
sink(&buffer); // $ MISSING: hasTaintFlow
793+
}
794+
795+
{
796+
let mut buffer = String::new();
797+
let _bytes = reader.read_to_string(&mut buffer)?;
798+
sink(&buffer); // $ MISSING: hasTaintFlow
799+
}
800+
801+
Ok(())
802+
}
803+
773804
#[tokio::main]
774805
async fn main() -> Result<(), Box<dyn std::error::Error>> {
775806
let case = std::env::args().nth(1).unwrap_or(String::from("1")).parse::<i64>().unwrap(); // $ Alert[rust/summary/taint-sources]
@@ -849,5 +880,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
849880
Err(e) => println!("error: {}", e),
850881
}
851882

883+
println!("test_rustls...");
884+
match test_rustls() {
885+
Ok(_) => println!("complete"),
886+
Err(e) => println!("error: {}", e),
887+
}
888+
852889
Ok(())
853890
}

0 commit comments

Comments
 (0)