@@ -106,10 +106,10 @@ async fn test_hyper_http(case: i64) -> Result<(), Box<dyn std::error::Error>> {
106
106
107
107
// make the request
108
108
println ! ( "sending request..." ) ;
109
- if ( case == 0 ) {
109
+ if case == 0 {
110
110
// simple flow case
111
111
let request = http:: Request :: builder ( ) . uri ( url) . body ( String :: from ( "" ) ) ?;
112
- let mut response = sender. send_request ( request) . await ?; // $ Alert[rust/summary/taint-sources]
112
+ let response = sender. send_request ( request) . await ?; // $ Alert[rust/summary/taint-sources]
113
113
sink ( & response) ; // $ hasTaintFlow=request
114
114
sink ( response) ; // $ hasTaintFlow=request
115
115
return Ok ( ( ) )
@@ -198,44 +198,10 @@ async fn test_hyper_http(case: i64) -> Result<(), Box<dyn std::error::Error>> {
198
198
Ok ( ( ) )
199
199
}
200
200
201
- use std:: fs;
202
-
203
- fn test_fs ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
204
- {
205
- let buffer: Vec < u8 > = std:: fs:: read ( "file.bin" ) ?; // $ Alert[rust/summary/taint-sources]
206
- sink ( buffer) ; // $ hasTaintFlow="file.bin"
207
- }
208
-
209
- {
210
- let buffer: Vec < u8 > = fs:: read ( "file.bin" ) ?; // $ Alert[rust/summary/taint-sources]
211
- sink ( buffer) ; // $ hasTaintFlow="file.bin"
212
- }
213
-
214
- {
215
- let buffer = fs:: read_to_string ( "file.txt" ) ?; // $ Alert[rust/summary/taint-sources]
216
- sink ( buffer) ; // $ hasTaintFlow="file.txt"
217
- }
218
-
219
- for entry in fs:: read_dir ( "directory" ) ? {
220
- let e = entry?;
221
- let path = e. path ( ) ; // $ Alert[rust/summary/taint-sources]
222
- let file_name = e. file_name ( ) ; // $ Alert[rust/summary/taint-sources]
223
- sink ( path) ; // $ hasTaintFlow
224
- sink ( file_name) ; // $ hasTaintFlow
225
- }
226
-
227
- {
228
- let target = fs:: read_link ( "symlink.txt" ) ?; // $ Alert[rust/summary/taint-sources]
229
- sink ( target) ; // $ hasTaintFlow="symlink.txt"
230
- }
231
-
232
- Ok ( ( ) )
233
- }
234
-
235
201
use std:: io:: Read ;
236
202
use std:: io:: BufRead ;
237
203
238
- fn test_io_fs ( ) -> std:: io:: Result < ( ) > {
204
+ fn test_io_stdin ( ) -> std:: io:: Result < ( ) > {
239
205
// --- stdin ---
240
206
241
207
{
@@ -256,46 +222,20 @@ fn test_io_fs() -> std::io::Result<()> {
256
222
sink ( & buffer) ; // $ hasTaintFlow
257
223
}
258
224
259
- {
260
- let mut buffer = [ 0 ; 100 ] ;
261
- std:: io:: stdin ( ) . read_exact ( & mut buffer) ?; // $ Alert[rust/summary/taint-sources]
262
- sink ( & buffer) ; // $ hasTaintFlow
263
- }
264
-
265
- for byte in std:: io:: stdin ( ) . bytes ( ) { // $ Alert[rust/summary/taint-sources]
266
- sink ( byte) ; // $ hasTaintFlow
267
- }
268
-
269
- // --- file ---
270
-
271
- let mut file = std:: fs:: File :: open ( "file.txt" ) ?; // $ Alert[rust/summary/taint-sources]
272
-
273
- {
274
- let mut buffer = [ 0u8 ; 100 ] ;
275
- let _bytes = file. read ( & mut buffer) ?;
276
- sink ( & buffer) ; // $ hasTaintFlow="file.txt"
277
- }
278
-
279
- {
280
- let mut buffer = Vec :: < u8 > :: new ( ) ;
281
- let _bytes = file. read_to_end ( & mut buffer) ?;
282
- sink ( & buffer) ; // $ hasTaintFlow="file.txt"
283
- }
284
-
285
225
{
286
226
let mut buffer = String :: new ( ) ;
287
- let _bytes = file . read_to_string ( & mut buffer) ?;
288
- sink ( & buffer) ; // $ hasTaintFlow="file.txt"
227
+ let _bytes = std :: io :: stdin ( ) . lock ( ) . read_to_string ( & mut buffer) ?; // $ Alert[rust/summary/taint-sources]
228
+ sink ( & buffer) ; // $ hasTaintFlow
289
229
}
290
230
291
231
{
292
232
let mut buffer = [ 0 ; 100 ] ;
293
- file . read_exact ( & mut buffer) ?;
294
- sink ( & buffer) ; // $ hasTaintFlow="file.txt"
233
+ std :: io :: stdin ( ) . read_exact ( & mut buffer) ?; // $ Alert[rust/summary/taint-sources]
234
+ sink ( & buffer) ; // $ hasTaintFlow
295
235
}
296
236
297
- for byte in file . bytes ( ) {
298
- sink ( byte) ; // $ hasTaintFlow="file.txt"
237
+ for byte in std :: io :: stdin ( ) . bytes ( ) { // $ Alert[rust/summary/taint-sources]
238
+ sink ( byte) ; // $ hasTaintFlow
299
239
}
300
240
301
241
// --- BufReader ---
@@ -307,7 +247,7 @@ fn test_io_fs() -> std::io::Result<()> {
307
247
}
308
248
309
249
{
310
- let mut reader = std:: io:: BufReader :: new ( std:: io:: stdin ( ) ) ; // $ Alert[rust/summary/taint-sources]
250
+ let reader = std:: io:: BufReader :: new ( std:: io:: stdin ( ) ) ; // $ Alert[rust/summary/taint-sources]
311
251
let data = reader. buffer ( ) ;
312
252
sink ( & data) ; // $ hasTaintFlow
313
253
}
@@ -324,73 +264,169 @@ fn test_io_fs() -> std::io::Result<()> {
324
264
let mut reader = std:: io:: BufReader :: new ( std:: io:: stdin ( ) ) ; // $ Alert[rust/summary/taint-sources]
325
265
reader. read_until ( b',' , & mut buffer) ?;
326
266
sink ( & buffer) ; // $ hasTaintFlow
267
+ sink ( buffer[ 0 ] ) ; // $ hasTaintFlow
327
268
}
328
269
329
270
{
330
- let mut buffer = Vec :: < u8 > :: new ( ) ;
331
271
let mut reader_split = std:: io:: BufReader :: new ( std:: io:: stdin ( ) ) . split ( b',' ) ; // $ Alert[rust/summary/taint-sources]
332
272
while let Some ( chunk) = reader_split. next ( ) {
333
273
sink ( chunk. unwrap ( ) ) ; // $ MISSING: hasTaintFlow
334
274
}
335
275
}
336
276
337
277
{
338
- let mut reader = std:: io:: BufReader :: new ( std:: io:: stdin ( ) ) ; // $ Alert[rust/summary/taint-sources]
278
+ let reader = std:: io:: BufReader :: new ( std:: io:: stdin ( ) ) ; // $ Alert[rust/summary/taint-sources]
339
279
for line in reader. lines ( ) {
340
280
sink ( line) ; // $ hasTaintFlow
341
281
}
342
282
}
343
283
344
284
{
345
- let mut reader = std:: io:: BufReader :: new ( std:: io:: stdin ( ) ) ; // $ Alert[rust/summary/taint-sources]
285
+ let reader = std:: io:: BufReader :: new ( std:: io:: stdin ( ) ) ; // $ Alert[rust/summary/taint-sources]
346
286
let line = reader. lines ( ) . nth ( 1 ) . unwrap ( ) ;
347
287
sink ( line. unwrap ( ) . clone ( ) ) ; // $ MISSING: hasTaintFlow
348
288
}
349
289
350
290
{
351
- let mut reader = std:: io:: BufReader :: new ( std:: io:: stdin ( ) ) ; // $ Alert[rust/summary/taint-sources]
291
+ let reader = std:: io:: BufReader :: new ( std:: io:: stdin ( ) ) ; // $ Alert[rust/summary/taint-sources]
352
292
let lines: Vec < _ > = reader. lines ( ) . collect ( ) ;
353
293
sink ( lines[ 1 ] . as_ref ( ) . unwrap ( ) . clone ( ) ) ; // $ MISSING: hasTaintFlow
354
294
}
355
295
296
+ Ok ( ( ) )
297
+ }
298
+
299
+ use std:: fs;
300
+
301
+ fn test_fs ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
302
+ {
303
+ let buffer: Vec < u8 > = std:: fs:: read ( "file.bin" ) ?; // $ Alert[rust/summary/taint-sources]
304
+ sink ( buffer) ; // $ hasTaintFlow="file.bin"
305
+ }
306
+
307
+ {
308
+ let buffer: Vec < u8 > = fs:: read ( "file.bin" ) ?; // $ Alert[rust/summary/taint-sources]
309
+ sink ( buffer) ; // $ hasTaintFlow="file.bin"
310
+ }
311
+
312
+ {
313
+ let buffer = fs:: read_to_string ( "file.txt" ) ?; // $ Alert[rust/summary/taint-sources]
314
+ sink ( buffer) ; // $ hasTaintFlow="file.txt"
315
+ }
316
+
317
+ for entry in fs:: read_dir ( "directory" ) ? {
318
+ let e = entry?;
319
+ let path = e. path ( ) ; // $ Alert[rust/summary/taint-sources]
320
+ let file_name = e. file_name ( ) ; // $ Alert[rust/summary/taint-sources]
321
+ sink ( path) ; // $ hasTaintFlow
322
+ sink ( file_name) ; // $ hasTaintFlow
323
+ }
324
+
325
+ {
326
+ let target = fs:: read_link ( "symlink.txt" ) ?; // $ Alert[rust/summary/taint-sources]
327
+ sink ( target) ; // $ hasTaintFlow="symlink.txt"
328
+ }
329
+
330
+ Ok ( ( ) )
331
+ }
332
+
333
+ fn test_io_file ( ) -> std:: io:: Result < ( ) > {
334
+ // --- file ---
335
+
336
+ let mut file = std:: fs:: File :: open ( "file.txt" ) ?; // $ Alert[rust/summary/taint-sources]
337
+
338
+ {
339
+ let mut buffer = [ 0u8 ; 100 ] ;
340
+ let _bytes = file. read ( & mut buffer) ?;
341
+ sink ( & buffer) ; // $ hasTaintFlow="file.txt"
342
+ }
343
+
344
+ {
345
+ let mut buffer = Vec :: < u8 > :: new ( ) ;
346
+ let _bytes = file. read_to_end ( & mut buffer) ?;
347
+ sink ( & buffer) ; // $ hasTaintFlow="file.txt"
348
+ }
349
+
350
+ {
351
+ let mut buffer = String :: new ( ) ;
352
+ let _bytes = file. read_to_string ( & mut buffer) ?;
353
+ sink ( & buffer) ; // $ hasTaintFlow="file.txt"
354
+ }
355
+
356
+ {
357
+ let mut buffer = [ 0 ; 100 ] ;
358
+ file. read_exact ( & mut buffer) ?;
359
+ sink ( & buffer) ; // $ hasTaintFlow="file.txt"
360
+ }
361
+
362
+ for byte in file. bytes ( ) {
363
+ sink ( byte) ; // $ hasTaintFlow="file.txt"
364
+ }
365
+
356
366
// --- misc operations ---
357
367
358
368
{
359
369
let mut buffer = String :: new ( ) ;
360
- let mut file1 = std:: fs:: File :: open ( "file.txt" ) ?; // $ Alert[rust/summary/taint-sources]
361
- let mut file2 = std:: fs:: File :: open ( "another_file.txt" ) ?; // $ Alert[rust/summary/taint-sources]
370
+ let file1 = std:: fs:: File :: open ( "file.txt" ) ?; // $ Alert[rust/summary/taint-sources]
371
+ let file2 = std:: fs:: File :: open ( "another_file.txt" ) ?; // $ Alert[rust/summary/taint-sources]
362
372
let mut reader = file1. chain ( file2) ;
363
373
reader. read_to_string ( & mut buffer) ?;
364
374
sink ( & buffer) ; // $ hasTaintFlow="file.txt" hasTaintFlow="another_file.txt"
365
375
}
366
376
367
377
{
368
378
let mut buffer = String :: new ( ) ;
369
- let mut file1 = std:: fs:: File :: open ( "file.txt" ) ?; // $ Alert[rust/summary/taint-sources]
379
+ let file1 = std:: fs:: File :: open ( "file.txt" ) ?; // $ Alert[rust/summary/taint-sources]
370
380
let mut reader = file1. take ( 100 ) ;
371
381
reader. read_to_string ( & mut buffer) ?;
372
382
sink ( & buffer) ; // $ hasTaintFlow="file.txt"
373
383
}
374
384
375
- {
376
- let mut buffer = String :: new ( ) ;
377
- let _bytes = std:: io:: stdin ( ) . lock ( ) . read_to_string ( & mut buffer) ?; // $ Alert[rust/summary/taint-sources]
378
- sink ( & buffer) ; // $ hasTaintFlow
379
- }
380
-
381
385
Ok ( ( ) )
382
386
}
383
387
384
388
#[ tokio:: main]
385
389
async fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
386
390
let case = std:: env:: args ( ) . nth ( 1 ) . unwrap_or ( String :: from ( "1" ) ) . parse :: < i64 > ( ) . unwrap ( ) ; // $ Alert[rust/summary/taint-sources]
387
391
392
+ println ! ( "test_env_vars..." ) ;
393
+ test_env_vars ( ) ;
394
+
395
+ /*println!("test_env_args...");
396
+ test_env_args();*/
397
+
398
+ println ! ( "test_env_dirs..." ) ;
399
+ test_env_dirs ( ) ;
400
+
401
+ /*println!("test_reqwest...");
402
+ match futures::executor::block_on(test_reqwest()) {
403
+ Ok(_) => println!("complete"),
404
+ Err(e) => println!("error: {}", e),
405
+ }*/
406
+
388
407
println ! ( "test_hyper_http..." ) ;
389
408
match futures:: executor:: block_on ( test_hyper_http ( case) ) {
390
409
Ok ( _) => println ! ( "complete" ) ,
391
410
Err ( e) => println ! ( "error: {}" , e) ,
392
411
}
393
- println ! ( "" ) ;
412
+
413
+ /*println!("test_io_stdin...");
414
+ match test_io_stdin() {
415
+ Ok(_) => println!("complete"),
416
+ Err(e) => println!("error: {}", e),
417
+ }*/
418
+
419
+ println ! ( "test_fs..." ) ;
420
+ match test_fs ( ) {
421
+ Ok ( _) => println ! ( "complete" ) ,
422
+ Err ( e) => println ! ( "error: {}" , e) ,
423
+ }
424
+
425
+ println ! ( "test_io_file..." ) ;
426
+ match test_io_file ( ) {
427
+ Ok ( _) => println ! ( "complete" ) ,
428
+ Err ( e) => println ! ( "error: {}" , e) ,
429
+ }
394
430
395
431
Ok ( ( ) )
396
432
}
0 commit comments