Skip to content

Commit 7439b0c

Browse files
committed
Rust: Add models for tokio (io).
1 parent 627496d commit 7439b0c

File tree

3 files changed

+88
-28
lines changed

3 files changed

+88
-28
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/rust-all
4+
extensible: sourceModel
5+
data:
6+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::stdin::stdin", "ReturnValue", "stdin", "manual"]
7+
- addsTo:
8+
pack: codeql/rust-all
9+
extensible: summaryModel
10+
data:
11+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "<crate::io::util::buf_reader::BufReader>::new", "Argument[0]", "ReturnValue", "taint", "manual"]
12+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_buf_read_ext::AsyncBufReadExt::fill_buf", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
13+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "<crate::io::util::buf_reader::BufReader>::buffer", "Argument[self]", "ReturnValue", "taint", "manual"]
14+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read", "Argument[self]", "Argument[0].Reference", "taint", "manual"]
15+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_to_string", "Argument[self]", "Argument[0].Reference", "taint", "manual"]
16+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_to_end", "Argument[self]", "Argument[0].Reference", "taint", "manual"]
17+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_exact", "Argument[self]", "Argument[0].Reference", "taint", "manual"]
18+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_buf_read_ext::AsyncBufReadExt::read_line", "Argument[self]", "Argument[0].Reference", "taint", "manual"]
19+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_buf_read_ext::AsyncBufReadExt::read_until", "Argument[self]", "Argument[1].Reference", "taint", "manual"]
20+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_buf_read_ext::AsyncBufReadExt::split", "Argument[self]", "ReturnValue", "taint", "manual"]
21+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "<crate::io::util::split::Split>::next_segment", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)].Field[crate::option::Option::Some(0)]", "taint", "manual"]
22+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_buf_read_ext::AsyncBufReadExt::lines", "Argument[self]", "ReturnValue", "taint", "manual"]
23+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "<crate::io::util::lines::Lines>::next_line", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)].Field[crate::option::Option::Some(0)]", "taint", "manual"]
24+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_buf", "Argument[self]", "Argument[0].Reference", "taint", "manual"]
25+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_u8", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
26+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_u8_le", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
27+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_u16", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
28+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_u16_le", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
29+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_u32", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
30+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_u32_le", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
31+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_u64", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
32+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_u64_le", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
33+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_u128", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
34+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_u128_le", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
35+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_i8", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
36+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_i8_le", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
37+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_i16", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
38+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_i16_le", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
39+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_i32", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
40+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_i32_le", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
41+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_i64", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
42+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_i64_le", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
43+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_i128", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
44+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_i128_le", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
45+
- ["repo:https://github.com/tokio-rs/tokio:tokio", "crate::io::util::async_read_ext::AsyncReadExt::read_f32", "Argument[self]", "ReturnValue.Future.Field[crate::result::Result::Ok(0)]", "taint", "manual"]
46+
- ["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"]
47+
- ["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"]
48+
- ["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"]

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@
3636
| test.rs:280:46:280:59 | ...::stdin | Flow source 'StdInSource' of type stdin (DEFAULT). |
3737
| test.rs:287:46:287:59 | ...::stdin | Flow source 'StdInSource' of type stdin (DEFAULT). |
3838
| test.rs:293:46:293:59 | ...::stdin | Flow source 'StdInSource' of type stdin (DEFAULT). |
39+
| test.rs:308:25:308:40 | ...::stdin | Flow source 'StdInSource' of type stdin (DEFAULT). |
40+
| test.rs:315:25:315:40 | ...::stdin | Flow source 'StdInSource' of type stdin (DEFAULT). |
41+
| test.rs:322:25:322:40 | ...::stdin | Flow source 'StdInSource' of type stdin (DEFAULT). |
42+
| test.rs:329:25:329:40 | ...::stdin | Flow source 'StdInSource' of type stdin (DEFAULT). |
43+
| test.rs:336:25:336:40 | ...::stdin | Flow source 'StdInSource' of type stdin (DEFAULT). |
44+
| test.rs:348:25:348:40 | ...::stdin | Flow source 'StdInSource' of type stdin (DEFAULT). |
45+
| test.rs:357:52:357:67 | ...::stdin | Flow source 'StdInSource' of type stdin (DEFAULT). |
46+
| test.rs:363:48:363:63 | ...::stdin | Flow source 'StdInSource' of type stdin (DEFAULT). |
47+
| test.rs:370:52:370:67 | ...::stdin | Flow source 'StdInSource' of type stdin (DEFAULT). |
48+
| test.rs:377:52:377:67 | ...::stdin | Flow source 'StdInSource' of type stdin (DEFAULT). |
49+
| test.rs:384:58:384:73 | ...::stdin | Flow source 'StdInSource' of type stdin (DEFAULT). |
50+
| test.rs:392:48:392:63 | ...::stdin | Flow source 'StdInSource' of type stdin (DEFAULT). |
3951
| test.rs:407:31:407:43 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
4052
| test.rs:412:31:412:38 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
4153
| test.rs:417:22:417:39 | ...::read_to_string | Flow source 'FileSource' of type file (DEFAULT). |

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

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -305,93 +305,93 @@ async fn test_tokio_stdin() -> Result<(), Box<dyn std::error::Error>> {
305305
// --- async reading from stdin ---
306306

307307
{
308-
let mut stdin = tokio::io::stdin(); // $ MISSING: Alert[rust/summary/taint-sources]
308+
let mut stdin = tokio::io::stdin(); // $ Alert[rust/summary/taint-sources]
309309
let mut buffer = [0u8; 100];
310310
let _bytes = stdin.read(&mut buffer).await?;
311-
sink(&buffer); // $ MISSING: hasTaintFlow
311+
sink(&buffer); // $ hasTaintFlow
312312
}
313313

314314
{
315-
let mut stdin = tokio::io::stdin(); // $ MISSING: Alert[rust/summary/taint-sources]
315+
let mut stdin = tokio::io::stdin(); // $ Alert[rust/summary/taint-sources]
316316
let mut buffer = Vec::<u8>::new();
317317
let _bytes = stdin.read_to_end(&mut buffer).await?;
318-
sink(&buffer); // $ MISSING: hasTaintFlow
318+
sink(&buffer); // $ hasTaintFlow
319319
}
320320

321321
{
322-
let mut stdin = tokio::io::stdin(); // $ MISSING: Alert[rust/summary/taint-sources]
322+
let mut stdin = tokio::io::stdin(); // $ Alert[rust/summary/taint-sources]
323323
let mut buffer = String::new();
324324
let _bytes = stdin.read_to_string(&mut buffer).await?;
325-
sink(&buffer); // $ MISSING: hasTaintFlow
325+
sink(&buffer); // $ hasTaintFlow
326326
}
327327

328328
{
329-
let mut stdin = tokio::io::stdin(); // $ MISSING: Alert[rust/summary/taint-sources]
329+
let mut stdin = tokio::io::stdin(); // $ Alert[rust/summary/taint-sources]
330330
let mut buffer = [0; 100];
331331
stdin.read_exact(&mut buffer).await?;
332-
sink(&buffer); // $ MISSING: hasTaintFlow
332+
sink(&buffer); // $ hasTaintFlow
333333
}
334334

335335
{
336-
let mut stdin = tokio::io::stdin(); // $ MISSING: Alert[rust/summary/taint-sources]
336+
let mut stdin = tokio::io::stdin(); // $ Alert[rust/summary/taint-sources]
337337
let v1 = stdin.read_u8().await?;
338338
let v2 = stdin.read_i16().await?;
339339
let v3 = stdin.read_f32().await?;
340340
let v4 = stdin.read_i64_le().await?;
341-
sink(v1); // $ MISSING: hasTaintFlow
342-
sink(v2); // $ MISSING: hasTaintFlow
343-
sink(v3); // $ MISSING: hasTaintFlow
344-
sink(v4); // $ MISSING: hasTaintFlow
341+
sink(v1); // $ hasTaintFlow
342+
sink(v2); // $ hasTaintFlow
343+
sink(v3); // $ hasTaintFlow
344+
sink(v4); // $ hasTaintFlow
345345
}
346346

347347
{
348-
let mut stdin = tokio::io::stdin(); // $ MISSING: Alert[rust/summary/taint-sources]
348+
let mut stdin = tokio::io::stdin(); // $ Alert[rust/summary/taint-sources]
349349
let mut buffer = bytes::BytesMut::new();
350350
stdin.read_buf(&mut buffer).await?;
351-
sink(&buffer); // $ MISSING: hasTaintFlow
351+
sink(&buffer); // $ hasTaintFlow
352352
}
353353

354354
// --- async reading from stdin (BufReader) ---
355355

356356
{
357-
let mut reader = tokio::io::BufReader::new(tokio::io::stdin()); // $ MISSING: Alert[rust/summary/taint-sources]
357+
let mut reader = tokio::io::BufReader::new(tokio::io::stdin()); // $ Alert[rust/summary/taint-sources]
358358
let data = reader.fill_buf().await?;
359-
sink(&data); // $ MISSING: hasTaintFlow
359+
sink(&data); // $ hasTaintFlow
360360
}
361361

362362
{
363-
let reader = tokio::io::BufReader::new(tokio::io::stdin()); // $ MISSING: Alert[rust/summary/taint-sources]
363+
let reader = tokio::io::BufReader::new(tokio::io::stdin()); // $ Alert[rust/summary/taint-sources]
364364
let data = reader.buffer();
365-
sink(&data); // $ MISSING: hasTaintFlow
365+
sink(&data); // $ hasTaintFlow
366366
}
367367

368368
{
369369
let mut buffer = String::new();
370-
let mut reader = tokio::io::BufReader::new(tokio::io::stdin()); // $ MISSING: Alert[rust/summary/taint-sources]
370+
let mut reader = tokio::io::BufReader::new(tokio::io::stdin()); // $ Alert[rust/summary/taint-sources]
371371
reader.read_line(&mut buffer).await?;
372-
sink(&buffer); // $ MISSING: hasTaintFlow
372+
sink(&buffer); // $ hasTaintFlow
373373
}
374374

375375
{
376376
let mut buffer = Vec::<u8>::new();
377-
let mut reader = tokio::io::BufReader::new(tokio::io::stdin()); // $ MISSING: Alert[rust/summary/taint-sources]
377+
let mut reader = tokio::io::BufReader::new(tokio::io::stdin()); // $ Alert[rust/summary/taint-sources]
378378
reader.read_until(b',', &mut buffer).await?;
379-
sink(&buffer); // $ MISSING: hasTaintFlow
380-
sink(buffer[0]); // $ MISSING: hasTaintFlow
379+
sink(&buffer); // $ hasTaintFlow
380+
sink(buffer[0]); // $ hasTaintFlow
381381
}
382382

383383
{
384-
let mut reader_split = tokio::io::BufReader::new(tokio::io::stdin()).split(b','); // $ MISSING: Alert[rust/summary/taint-sources]
385-
sink(reader_split.next_segment().await?.unwrap()); // $ MISSING: hasTaintFlow
384+
let mut reader_split = tokio::io::BufReader::new(tokio::io::stdin()).split(b','); // $ Alert[rust/summary/taint-sources]
385+
sink(reader_split.next_segment().await?.unwrap()); // $ hasTaintFlow
386386
while let Some(chunk) = reader_split.next_segment().await? {
387387
sink(chunk); // $ MISSING: hasTaintFlow
388388
}
389389
}
390390

391391
{
392-
let reader = tokio::io::BufReader::new(tokio::io::stdin()); // $ MISSING: Alert[rust/summary/taint-sources]
392+
let reader = tokio::io::BufReader::new(tokio::io::stdin()); // $ Alert[rust/summary/taint-sources]
393393
let mut lines = reader.lines();
394-
sink(lines.next_line().await?.unwrap()); // $ MISSING: hasTaintFlow
394+
sink(lines.next_line().await?.unwrap()); // $ hasTaintFlow
395395
while let Some(line) = lines.next_line().await? {
396396
sink(line); // $ MISSING: hasTaintFlow
397397
}

0 commit comments

Comments
 (0)