Skip to content

Commit 8f80762

Browse files
committed
wip
1 parent 578db15 commit 8f80762

File tree

2 files changed

+20
-28
lines changed

2 files changed

+20
-28
lines changed

rust/ql/lib/codeql/rust/internal/TypeMention.qll

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ class NonAliasPathTypeMention extends PathTypeMention {
113113

114114
NonAliasPathTypeMention() {
115115
resolved = [resolvePath(this), resolvePath(this).(Variant).getEnum().(TypeItemNode)] and
116-
not exists(resolved.(TypeAlias).getTypeRepr())
116+
not exists(resolved.(TypeAlias).getTypeRepr()) and
117+
not this = any(ImplItemNode i).getASelfPath() // handled by `ImplSelfMention`
117118
}
118119

119120
TypeItemNode getResolved() { result = resolved }
@@ -145,23 +146,6 @@ class NonAliasPathTypeMention extends PathTypeMention {
145146
private TypeMention getPositionalTypeArgument0(int i) {
146147
result = this.getSegment().getGenericArgList().getTypeArg(i)
147148
or
148-
// `Self` paths inside `impl` blocks have implicit type arguments that are
149-
// the type parameters of the `impl` block. For example, in
150-
//
151-
// ```rust
152-
// impl<T> Foo<T> {
153-
// fn m(self) -> Self {
154-
// self
155-
// }
156-
// }
157-
// ```
158-
//
159-
// the `Self` return type is shorthand for `Foo<T>`.
160-
exists(ImplItemNode node |
161-
this = node.getASelfPath() and
162-
result = node.(ImplItemNode).getSelfPath().getSegment().getGenericArgList().getTypeArg(i)
163-
)
164-
or
165149
// `Option::<i32>::Some` is valid in addition to `Option::Some::<i32>`
166150
resolvePath(this) instanceof Variant and
167151
result = this.getQualifier().getSegment().getGenericArgList().getTypeArg(i)
@@ -260,6 +244,14 @@ class NonAliasPathTypeMention extends PathTypeMention {
260244
}
261245
}
262246

247+
class ImplSelfMention extends PathTypeMention {
248+
private ImplItemNode impl;
249+
250+
ImplSelfMention() { this = impl.getASelfPath() }
251+
252+
override Type resolveTypeAt(TypePath typePath) { result = resolveImplSelfType(impl, typePath) }
253+
}
254+
263255
class PathTypeReprMention extends TypeMention, PathTypeRepr {
264256
private PathTypeMention path;
265257

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ async fn test_futures_rustls_futures_io() -> io::Result<()> {
4242
{
4343
// using the `AsyncReadExt::read` extension method (higher-level)
4444
let mut buffer1 = [0u8; 64];
45-
let bytes_read1 = futures::io::AsyncReadExt::read(&mut reader, &mut buffer1).await?; // we cannot resolve the `read` call, which comes from `impl<R: AsyncRead + ?Sized> AsyncReadExt for R {}` in `async_read_ext.rs`
45+
let bytes_read1 = futures::io::AsyncReadExt::read(&mut reader, &mut buffer1).await?;
4646
sink(&buffer1[..bytes_read1]); // $ hasTaintFlow=url
4747

4848
let mut buffer2 = [0u8; 64];
49-
let bytes_read2 = reader.read(&mut buffer2).await?; // we cannot resolve the `read` call, which comes from `impl<R: AsyncRead + ?Sized> AsyncReadExt for R {}` in `async_read_ext.rs`
49+
let bytes_read2 = reader.read(&mut buffer2).await?;
5050

5151
sink(&buffer2[..bytes_read2]); // $ hasTaintFlow=url
5252
}
@@ -80,7 +80,7 @@ async fn test_futures_rustls_futures_io() -> io::Result<()> {
8080

8181
{
8282
// using the `AsyncBufReadExt::fill_buf` extension method (higher-level)
83-
let buffer = reader2.fill_buf().await?; // we cannot resolve the `fill_buf` call, which comes from `impl<R: AsyncBufRead + ?Sized> AsyncBufReadExt for R {}` in `async_buf_read_ext.rs`
83+
let buffer = reader2.fill_buf().await?;
8484
sink(buffer); // $ hasTaintFlow=url
8585
}
8686

@@ -100,11 +100,11 @@ async fn test_futures_rustls_futures_io() -> io::Result<()> {
100100
{
101101
// using the `AsyncReadExt::read` extension method (higher-level)
102102
let mut buffer1 = [0u8; 64];
103-
let bytes_read1 = futures::io::AsyncReadExt::read(&mut reader2, &mut buffer1).await?; // we cannot resolve the `read` call, which comes from `impl<R: AsyncRead + ?Sized> AsyncReadExt for R {}` in `async_read_ext.rs`
103+
let bytes_read1 = futures::io::AsyncReadExt::read(&mut reader2, &mut buffer1).await?;
104104
sink(&buffer1[..bytes_read1]); // $ hasTaintFlow=url
105105

106106
let mut buffer2 = [0u8; 64];
107-
let bytes_read2 = reader2.read(&mut buffer2).await?; // we cannot resolve the `read` call, which comes from `impl<R: AsyncRead + ?Sized> AsyncReadExt for R {}` in `async_read_ext.rs`
107+
let bytes_read2 = reader2.read(&mut buffer2).await?;
108108
sink(&buffer2[..bytes_read2]); // $ hasTaintFlow=url
109109
}
110110

@@ -122,34 +122,34 @@ async fn test_futures_rustls_futures_io() -> io::Result<()> {
122122

123123
{
124124
// using the `AsyncBufReadExt::fill_buf` extension method (higher-level)
125-
let buffer = reader2.fill_buf().await?; // we cannot resolve the `fill_buf` call, which comes from `impl<R: AsyncBufRead + ?Sized> AsyncBufReadExt for R {}` in `async_buf_read_ext.rs`
125+
let buffer = reader2.fill_buf().await?;
126126
sink(buffer); // $ hasTaintFlow=url
127127
}
128128

129129
{
130130
// using the `AsyncBufReadExt::read_until` extension method
131131
let mut line = Vec::new();
132-
let _bytes_read = reader2.read_until(b'\n', &mut line).await?; // we cannot resolve the `read_until` call, which comes from `impl<R: AsyncBufRead + ?Sized> AsyncBufReadExt for R {}` in `async_buf_read_ext.rs`
132+
let _bytes_read = reader2.read_until(b'\n', &mut line).await?;
133133
sink(&line); // $ hasTaintFlow=url
134134
}
135135

136136
{
137137
// using the `AsyncBufReadExt::read_line` extension method
138138
let mut line = String::new();
139-
let _bytes_read = reader2.read_line(&mut line).await?; // we cannot resolve the `read_line` call, which comes from `impl<R: AsyncBufRead + ?Sized> AsyncBufReadExt for R {}` in `async_buf_read_ext.rs`
139+
let _bytes_read = reader2.read_line(&mut line).await?;
140140
sink(&line); // $ hasTaintFlow=url
141141
}
142142

143143
{
144144
// using the `AsyncBufReadExt::read_to_end` extension method
145145
let mut buffer = Vec::with_capacity(1024);
146-
let _bytes_read = reader2.read_to_end(&mut buffer).await?; // we cannot resolve the `read` call, which comes from `impl<R: AsyncRead + ?Sized> AsyncReadExt for R {}` in `async_read_ext.rs`
146+
let _bytes_read = reader2.read_to_end(&mut buffer).await?;
147147
sink(&buffer); // $ hasTaintFlow=url
148148
}
149149

150150
{
151151
// using the `AsyncBufReadExt::lines` extension method
152-
let mut lines_stream = reader2.lines(); // we cannot resolve the `lines` call, which comes from `impl<R: AsyncBufRead + ?Sized> AsyncBufReadExt for R {}` in `async_buf_read_ext.rs`
152+
let mut lines_stream = reader2.lines();
153153
sink(lines_stream.next().await.unwrap()); // $ MISSING: hasTaintFlow=url
154154
while let Some(line) = lines_stream.next().await {
155155
sink(line.unwrap()); // $ MISSING: hasTaintFlow

0 commit comments

Comments
 (0)