Skip to content

Commit 13f6de9

Browse files
committed
Rust: Add source / basic basic models.
1 parent b78d51e commit 13f6de9

File tree

6 files changed

+33
-12
lines changed

6 files changed

+33
-12
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/rust-all
4+
extensible: sourceModel
5+
data:
6+
- ["repo:https://github.com/async-rs/async-std:async-std", "<crate::net::tcp::stream::TcpStream>::connect", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "remote", "manual"]

rust/ql/lib/codeql/rust/frameworks/futures.model.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ extensions:
44
extensible: summaryModel
55
data:
66
- ["repo:https://github.com/rust-lang/futures-rs:futures-executor", "crate::local_pool::block_on", "Argument[0]", "ReturnValue", "value", "manual"]
7+
- ["repo:https://github.com/rust-lang/futures-rs:futures-util", "<crate::io::buf_reader::BufReader>::new", "Argument[0]", "ReturnValue", "taint", "manual"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/rust-all
4+
extensible: sourceModel
5+
data:
6+
- ["repo:https://github.com/rustls/rustls:rustls", "<crate::client::client_conn::connection::ClientConnection>::new", "ReturnValue.Field[crate::result::Result::Ok(0)]", "remote", "manual"]
7+
- addsTo:
8+
pack: codeql/rust-all
9+
extensible: summaryModel
10+
data:
11+
- ["repo:https://github.com/quininer/futures-rustls:futures-rustls", "<crate::TlsConnector>::connect", "Argument[1]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
12+
- ["repo:https://github.com/rustls/rustls:rustls", "<crate::conn::ConnectionCommon>::reader", "Argument[self]", "ReturnValue", "taint", "manual"]

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@
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:779:22:779:50 | ...::new | Flow source 'RemoteSource' of type remote (DEFAULT). |
7879
| test.rs:806:16:806:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
7980
| test.rs:806:16:806:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
81+
| test_futures_io.rs:19:15:19:32 | ...::connect | Flow source 'RemoteSource' of type remote (DEFAULT). |
8082
| web_frameworks.rs:12:31:12:31 | a | Flow source 'RemoteSource' of type remote (DEFAULT). |
8183
| web_frameworks.rs:12:31:12:31 | a | Flow source 'RemoteSource' of type remote (DEFAULT). |
8284
| 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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -776,9 +776,9 @@ fn test_rustls() -> std::io::Result<()> {
776776
.with_no_client_auth();
777777
let server_name = rustls::pki_types::ServerName::try_from("www.example.com").unwrap();
778778
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]
779+
let mut client = rustls::ClientConnection::new(config_arc, server_name).unwrap(); // $ Alert[rust/summary/taint-sources]
780780
let mut reader = client.reader();
781-
sink(&reader); // $ MISSING: hasTaintFlow
781+
sink(&reader); // $ hasTaintFlow=config_arc
782782

783783
{
784784
let mut buffer = [0u8; 100];
@@ -789,13 +789,13 @@ fn test_rustls() -> std::io::Result<()> {
789789
{
790790
let mut buffer = Vec::<u8>::new();
791791
let _bytes = reader.read_to_end(&mut buffer)?;
792-
sink(&buffer); // $ MISSING: hasTaintFlow
792+
sink(&buffer); // $ hasTaintFlow=config_arc
793793
}
794794

795795
{
796796
let mut buffer = String::new();
797797
let _bytes = reader.read_to_string(&mut buffer)?;
798-
sink(&buffer); // $ MISSING: hasTaintFlow
798+
sink(&buffer); // $ hasTaintFlow=config_arc
799799
}
800800

801801
Ok(())

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ use async_std::net::TcpStream;
1616

1717
async fn test_futures_rustls_futures_io() -> io::Result<()> {
1818
let url = "www.example.com:443";
19-
let tcp = TcpStream::connect(url).await?; // $ MISSING: Alert[rust/summary/taint-sources]
20-
sink(&tcp); // $ MISSING: hasTaintFlow
19+
let tcp = TcpStream::connect(url).await?; // $ Alert[rust/summary/taint-sources]
20+
sink(&tcp); // $ hasTaintFlow=url
2121
let config = rustls::ClientConfig::builder()
2222
.with_root_certificates(rustls::RootCertStore::empty())
2323
.with_no_client_auth();
2424
let connector = TlsConnector::from(Arc::new(config));
2525
let server_name = rustls::pki_types::ServerName::try_from("www.example.com").unwrap();
2626
let mut reader = connector.connect(server_name, tcp).await?;
27-
sink(&reader); // $ MISSING: hasTaintFlow
27+
sink(&reader); // $ hasTaintFlow=url
2828

2929
{
3030
// using the `AsyncRead` trait (low-level)
3131
let mut buffer = [0u8; 64];
3232
let mut pinned = Pin::new(&mut reader);
33-
sink(&pinned); // $ MISSING: hasTaintFlow
33+
sink(&pinned); // $ hasTaintFlow=url
3434
let mut cx = Context::from_waker(futures::task::noop_waker_ref());
3535
let bytes_read = pinned.poll_read(&mut cx, &mut buffer);
3636
if let Poll::Ready(Ok(n)) = bytes_read {
@@ -51,12 +51,12 @@ async fn test_futures_rustls_futures_io() -> io::Result<()> {
5151
}
5252

5353
let mut reader2 = futures::io::BufReader::new(reader);
54-
sink(&reader2); // $ MISSING: hasTaintFlow
54+
sink(&reader2); // $ hasTaintFlow=url
5555

5656
{
5757
// using the `AsyncBufRead` trait (low-level)
5858
let mut pinned = Pin::new(&mut reader2);
59-
sink(&pinned); // $ MISSING: hasTaintFlow
59+
sink(&pinned); // $ hasTaintFlow=url
6060
let mut cx = Context::from_waker(futures::task::noop_waker_ref());
6161
let buffer = pinned.poll_fill_buf(&mut cx);
6262
if let Poll::Ready(Ok(buf)) = buffer {
@@ -87,7 +87,7 @@ async fn test_futures_rustls_futures_io() -> io::Result<()> {
8787
// using the `AsyncRead` trait (low-level)
8888
let mut buffer = [0u8; 64];
8989
let mut pinned = Pin::new(&mut reader2);
90-
sink(&pinned); // $ MISSING: hasTaintFlow
90+
sink(&pinned); // $ hasTaintFlow=url
9191
let mut cx = Context::from_waker(futures::task::noop_waker_ref());
9292
let bytes_read = pinned.poll_read(&mut cx, &mut buffer);
9393
sink(&buffer); // $ MISSING: hasTaintFlow=url
@@ -110,7 +110,7 @@ async fn test_futures_rustls_futures_io() -> io::Result<()> {
110110
{
111111
// using the `AsyncBufRead` trait (low-level)
112112
let mut pinned = Pin::new(&mut reader2);
113-
sink(&pinned); // $ MISSING: hasTaintFlow
113+
sink(&pinned); // $ hasTaintFlow=url
114114
let mut cx = Context::from_waker(futures::task::noop_waker_ref());
115115
let buffer = pinned.poll_fill_buf(&mut cx);
116116
sink(&buffer); // $ MISSING: hasTaintFlow=url

0 commit comments

Comments
 (0)