@@ -106,10 +106,10 @@ async fn test_hyper_http(case: i64) -> Result<(), Box<dyn std::error::Error>> {
106106
107107 // make the request
108108 println ! ( "sending request..." ) ;
109- if ( case == 0 ) {
109+ if case == 0 {
110110 // simple flow case
111111 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]
113113 sink ( & response) ; // $ hasTaintFlow=request
114114 sink ( response) ; // $ hasTaintFlow=request
115115 return Ok ( ( ) )
@@ -198,44 +198,10 @@ async fn test_hyper_http(case: i64) -> Result<(), Box<dyn std::error::Error>> {
198198 Ok ( ( ) )
199199}
200200
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-
235201use std:: io:: Read ;
236202use std:: io:: BufRead ;
237203
238- fn test_io_fs ( ) -> std:: io:: Result < ( ) > {
204+ fn test_io_stdin ( ) -> std:: io:: Result < ( ) > {
239205 // --- stdin ---
240206
241207 {
@@ -256,46 +222,20 @@ fn test_io_fs() -> std::io::Result<()> {
256222 sink ( & buffer) ; // $ hasTaintFlow
257223 }
258224
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-
285225 {
286226 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
289229 }
290230
291231 {
292232 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
295235 }
296236
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
299239 }
300240
301241 // --- BufReader ---
@@ -307,7 +247,7 @@ fn test_io_fs() -> std::io::Result<()> {
307247 }
308248
309249 {
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]
311251 let data = reader. buffer ( ) ;
312252 sink ( & data) ; // $ hasTaintFlow
313253 }
@@ -324,73 +264,169 @@ fn test_io_fs() -> std::io::Result<()> {
324264 let mut reader = std:: io:: BufReader :: new ( std:: io:: stdin ( ) ) ; // $ Alert[rust/summary/taint-sources]
325265 reader. read_until ( b',' , & mut buffer) ?;
326266 sink ( & buffer) ; // $ hasTaintFlow
267+ sink ( buffer[ 0 ] ) ; // $ hasTaintFlow
327268 }
328269
329270 {
330- let mut buffer = Vec :: < u8 > :: new ( ) ;
331271 let mut reader_split = std:: io:: BufReader :: new ( std:: io:: stdin ( ) ) . split ( b',' ) ; // $ Alert[rust/summary/taint-sources]
332272 while let Some ( chunk) = reader_split. next ( ) {
333273 sink ( chunk. unwrap ( ) ) ; // $ MISSING: hasTaintFlow
334274 }
335275 }
336276
337277 {
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]
339279 for line in reader. lines ( ) {
340280 sink ( line) ; // $ hasTaintFlow
341281 }
342282 }
343283
344284 {
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]
346286 let line = reader. lines ( ) . nth ( 1 ) . unwrap ( ) ;
347287 sink ( line. unwrap ( ) . clone ( ) ) ; // $ MISSING: hasTaintFlow
348288 }
349289
350290 {
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]
352292 let lines: Vec < _ > = reader. lines ( ) . collect ( ) ;
353293 sink ( lines[ 1 ] . as_ref ( ) . unwrap ( ) . clone ( ) ) ; // $ MISSING: hasTaintFlow
354294 }
355295
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+
356366 // --- misc operations ---
357367
358368 {
359369 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]
362372 let mut reader = file1. chain ( file2) ;
363373 reader. read_to_string ( & mut buffer) ?;
364374 sink ( & buffer) ; // $ hasTaintFlow="file.txt" hasTaintFlow="another_file.txt"
365375 }
366376
367377 {
368378 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]
370380 let mut reader = file1. take ( 100 ) ;
371381 reader. read_to_string ( & mut buffer) ?;
372382 sink ( & buffer) ; // $ hasTaintFlow="file.txt"
373383 }
374384
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-
381385 Ok ( ( ) )
382386}
383387
384388#[ tokio:: main]
385389async fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
386390 let case = std:: env:: args ( ) . nth ( 1 ) . unwrap_or ( String :: from ( "1" ) ) . parse :: < i64 > ( ) . unwrap ( ) ; // $ Alert[rust/summary/taint-sources]
387391
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+
388407 println ! ( "test_hyper_http..." ) ;
389408 match futures:: executor:: block_on ( test_hyper_http ( case) ) {
390409 Ok ( _) => println ! ( "complete" ) ,
391410 Err ( e) => println ! ( "error: {}" , e) ,
392411 }
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+ }
394430
395431 Ok ( ( ) )
396432}
0 commit comments