Skip to content

Commit 307424e

Browse files
committed
Rust: Add source tests for tokio (stdin).
1 parent dcc488c commit 307424e

File tree

2 files changed

+98
-11
lines changed

2 files changed

+98
-11
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
| test.rs:278:46:278:59 | ...::stdin | Flow source 'StdInSource' of type stdin (DEFAULT). |
3737
| test.rs:285:46:285:59 | ...::stdin | Flow source 'StdInSource' of type stdin (DEFAULT). |
3838
| test.rs:291:46:291:59 | ...::stdin | Flow source 'StdInSource' of type stdin (DEFAULT). |
39-
| test.rs:303:31:303:43 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
40-
| test.rs:308:31:308:38 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
41-
| test.rs:313:22:313:39 | ...::read_to_string | Flow source 'FileSource' of type file (DEFAULT). |
42-
| test.rs:319:22:319:25 | path | Flow source 'FileSource' of type file (DEFAULT). |
43-
| test.rs:320:27:320:35 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
44-
| test.rs:326:22:326:34 | ...::read_link | Flow source 'FileSource' of type file (DEFAULT). |
45-
| test.rs:336:20:336:38 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
46-
| test.rs:370:21:370:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
47-
| test.rs:371:21:371:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
48-
| test.rs:379:21:379:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
49-
| test.rs:390:16:390:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |
39+
| test.rs:384:31:384:43 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
40+
| test.rs:389:31:389:38 | ...::read | Flow source 'FileSource' of type file (DEFAULT). |
41+
| test.rs:394:22:394:39 | ...::read_to_string | Flow source 'FileSource' of type file (DEFAULT). |
42+
| test.rs:400:22:400:25 | path | Flow source 'FileSource' of type file (DEFAULT). |
43+
| test.rs:401:27:401:35 | file_name | Flow source 'FileSource' of type file (DEFAULT). |
44+
| test.rs:407:22:407:34 | ...::read_link | Flow source 'FileSource' of type file (DEFAULT). |
45+
| test.rs:417:20:417:38 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
46+
| test.rs:451:21:451:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
47+
| test.rs:452:21:452:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
48+
| test.rs:460:21:460:39 | ...::open | Flow source 'FileSource' of type file (DEFAULT). |
49+
| test.rs:471:16:471:29 | ...::args | Flow source 'CommandLineArgs' of type commandargs (DEFAULT). |

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

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,87 @@ fn test_io_stdin() -> std::io::Result<()> {
296296
Ok(())
297297
}
298298

299+
use tokio::io::{AsyncReadExt, AsyncBufReadExt};
300+
301+
async fn test_tokio_stdin() -> Result<(), Box<dyn std::error::Error>> {
302+
303+
// --- async reading from stdin ---
304+
305+
{
306+
let mut stdin = tokio::io::stdin(); // $ MISSING: Alert[rust/summary/taint-sources]
307+
let mut buffer = [0u8; 100];
308+
let _bytes = stdin.read(&mut buffer).await?;
309+
sink(&buffer); // $ MISSING: hasTaintFlow
310+
}
311+
312+
{
313+
let mut stdin = tokio::io::stdin(); // $ MISSING: Alert[rust/summary/taint-sources]
314+
let mut buffer = Vec::<u8>::new();
315+
let _bytes = stdin.read_to_end(&mut buffer).await?;
316+
sink(&buffer); // $ MISSING: hasTaintFlow
317+
}
318+
319+
{
320+
let mut stdin = tokio::io::stdin(); // $ MISSING: Alert[rust/summary/taint-sources]
321+
let mut buffer = String::new();
322+
let _bytes = stdin.read_to_string(&mut buffer).await?;
323+
sink(&buffer); // $ MISSING: hasTaintFlow
324+
}
325+
326+
{
327+
let mut stdin = tokio::io::stdin(); // $ MISSING: Alert[rust/summary/taint-sources]
328+
let mut buffer = [0; 100];
329+
stdin.read_exact(&mut buffer).await?;
330+
sink(&buffer); // $ MISSING: hasTaintFlow
331+
}
332+
333+
// --- async reading from stdin (BufReader) ---
334+
335+
{
336+
let mut reader = tokio::io::BufReader::new(tokio::io::stdin()); // $ MISSING: Alert[rust/summary/taint-sources]
337+
let data = reader.fill_buf().await?;
338+
sink(&data); // $ MISSING: hasTaintFlow
339+
}
340+
341+
{
342+
let reader = tokio::io::BufReader::new(tokio::io::stdin()); // $ MISSING: Alert[rust/summary/taint-sources]
343+
let data = reader.buffer();
344+
sink(&data); // $ MISSING: hasTaintFlow
345+
}
346+
347+
{
348+
let mut buffer = String::new();
349+
let mut reader = tokio::io::BufReader::new(tokio::io::stdin()); // $ MISSING: Alert[rust/summary/taint-sources]
350+
reader.read_line(&mut buffer).await?;
351+
sink(&buffer); // $ MISSING: hasTaintFlow
352+
}
353+
354+
{
355+
let mut buffer = Vec::<u8>::new();
356+
let mut reader = tokio::io::BufReader::new(tokio::io::stdin()); // $ MISSING: Alert[rust/summary/taint-sources]
357+
reader.read_until(b',', &mut buffer).await?;
358+
sink(&buffer); // $ MISSING: hasTaintFlow
359+
sink(buffer[0]); // $ MISSING: hasTaintFlow
360+
}
361+
362+
{
363+
let mut reader_split = tokio::io::BufReader::new(tokio::io::stdin()).split(b','); // $ MISSING: Alert[rust/summary/taint-sources]
364+
while let Some(chunk) = reader_split.next_segment().await? {
365+
sink(chunk); // $ MISSING: hasTaintFlow
366+
}
367+
}
368+
369+
{
370+
let reader = tokio::io::BufReader::new(tokio::io::stdin()); // $ MISSING: Alert[rust/summary/taint-sources]
371+
let mut lines = reader.lines();
372+
while let Some(line) = lines.next_line().await? {
373+
sink(line); // $ hasTai
374+
}
375+
}
376+
377+
Ok(())
378+
}
379+
299380
use std::fs;
300381

301382
fn test_fs() -> Result<(), Box<dyn std::error::Error>> {
@@ -414,6 +495,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
414495
match test_io_stdin() {
415496
Ok(_) => println!("complete"),
416497
Err(e) => println!("error: {}", e),
498+
}
499+
500+
println!("test_tokio_stdin...");
501+
match futures::executor::block_on(test_tokio_stdin()) {
502+
Ok(_) => println!("complete"),
503+
Err(e) => println!("error: {}", e),
417504
}*/
418505

419506
println!("test_fs...");

0 commit comments

Comments
 (0)