@@ -74,7 +74,7 @@ pub struct Config<L: LibFuzzerType + Send + Sync + ?Sized> {
7474 pub inputs : SyncedDir ,
7575 pub readonly_inputs : Option < Vec < SyncedDir > > ,
7676 pub crashes : SyncedDir ,
77- pub crashdumps : SyncedDir ,
77+ pub crashdumps : Option < SyncedDir > ,
7878 pub target_exe : PathBuf ,
7979 pub target_env : HashMap < String , String > ,
8080 pub target_options : Vec < String > ,
@@ -131,7 +131,13 @@ where
131131 let resync = self . continuous_sync_inputs ( ) ;
132132 let new_inputs = self . config . inputs . monitor_results ( new_coverage, true ) ;
133133 let new_crashes = self . config . crashes . monitor_results ( new_result, true ) ;
134- let new_crashdumps = self . config . crashdumps . monitor_results ( new_crashdump, true ) ;
134+ let new_crashdumps = async {
135+ if let Some ( crashdumps) = & self . config . crashdumps {
136+ crashdumps. monitor_results ( new_crashdump, true ) . await
137+ } else {
138+ Ok ( ( ) )
139+ }
140+ } ;
135141
136142 let ( stats_sender, stats_receiver) = mpsc:: unbounded_channel ( ) ;
137143 let report_stats = report_runtime_stats ( stats_receiver, hb_client) ;
@@ -350,64 +356,66 @@ where
350356 }
351357 }
352358
353- // check for core dumps on Linux:
354- // note that collecting the dumps must be enabled by the template
355- #[ cfg( target_os = "linux" ) ]
356- if let Some ( pid) = pid {
357- // expect crash dump to exist in CWD
358- let filename = format ! ( "core.{pid}" ) ;
359- let dest_filename = dump_file_name. as_deref ( ) . unwrap_or ( OsStr :: new ( & filename) ) ;
360- let dest_path = self . config . crashdumps . local_path . join ( dest_filename) ;
361- match tokio:: fs:: rename ( & filename, & dest_path) . await {
362- Ok ( ( ) ) => {
363- info ! (
364- "moved crash dump {} to output directory: {}" ,
365- filename,
366- dest_path. display( )
367- ) ;
368- }
369- Err ( e) => {
370- if e. kind ( ) == std:: io:: ErrorKind :: NotFound {
371- // okay, no crash dump found
372- info ! ( "no crash dump found with name: {}" , filename) ;
373- } else {
374- return Err ( e) . context ( "moving crash dump to output directory" ) ;
359+ if let Some ( crashdumps) = & self . config . crashdumps {
360+ // check for core dumps on Linux:
361+ // note that collecting the dumps must be enabled by the template
362+ #[ cfg( target_os = "linux" ) ]
363+ if let Some ( pid) = pid {
364+ // expect crash dump to exist in CWD
365+ let filename = format ! ( "core.{pid}" ) ;
366+ let dest_filename = dump_file_name. as_deref ( ) . unwrap_or ( OsStr :: new ( & filename) ) ;
367+ let dest_path = crashdumps. local_path . join ( dest_filename) ;
368+ match tokio:: fs:: rename ( & filename, & dest_path) . await {
369+ Ok ( ( ) ) => {
370+ info ! (
371+ "moved crash dump {} to output directory: {}" ,
372+ filename,
373+ dest_path. display( )
374+ ) ;
375+ }
376+ Err ( e) => {
377+ if e. kind ( ) == std:: io:: ErrorKind :: NotFound {
378+ // okay, no crash dump found
379+ info ! ( "no crash dump found with name: {}" , filename) ;
380+ } else {
381+ return Err ( e) . context ( "moving crash dump to output directory" ) ;
382+ }
375383 }
376384 }
385+ } else {
386+ warn ! ( "no PID found for libfuzzer process" ) ;
377387 }
378- } else {
379- warn ! ( "no PID found for libfuzzer process" ) ;
380- }
381388
382- // check for crash dumps on Windows:
383- #[ cfg( target_os = "windows" ) ]
384- {
385- let dumpfile_extension = Some ( std:: ffi:: OsStr :: new ( "dmp" ) ) ;
386-
387- let mut working_dir = tokio:: fs:: read_dir ( "." ) . await ?;
388- let mut found_dump = false ;
389- while let Some ( next) = working_dir. next_entry ( ) . await ? {
390- if next. path ( ) . extension ( ) == dumpfile_extension {
391- // Windows dumps get a fixed filename so we will generate a random one,
392- // if there's no valid target crash name:
393- let dest_filename =
394- dump_file_name. unwrap_or_else ( || uuid:: Uuid :: new_v4 ( ) . to_string ( ) . into ( ) ) ;
395- let dest_path = self . config . crashdumps . local_path . join ( & dest_filename) ;
396- tokio:: fs:: rename ( next. path ( ) , & dest_path)
397- . await
398- . context ( "moving crash dump to output directory" ) ?;
399- info ! (
400- "moved crash dump {} to output directory: {}" ,
401- next. path( ) . display( ) ,
402- dest_path. display( )
403- ) ;
404- found_dump = true ;
405- break ;
389+ // check for crash dumps on Windows:
390+ #[ cfg( target_os = "windows" ) ]
391+ {
392+ let dumpfile_extension = Some ( std:: ffi:: OsStr :: new ( "dmp" ) ) ;
393+
394+ let mut working_dir = tokio:: fs:: read_dir ( "." ) . await ?;
395+ let mut found_dump = false ;
396+ while let Some ( next) = working_dir. next_entry ( ) . await ? {
397+ if next. path ( ) . extension ( ) == dumpfile_extension {
398+ // Windows dumps get a fixed filename so we will generate a random one,
399+ // if there's no valid target crash name:
400+ let dest_filename = dump_file_name
401+ . unwrap_or_else ( || uuid:: Uuid :: new_v4 ( ) . to_string ( ) . into ( ) ) ;
402+ let dest_path = crashdumps. local_path . join ( & dest_filename) ;
403+ tokio:: fs:: rename ( next. path ( ) , & dest_path)
404+ . await
405+ . context ( "moving crash dump to output directory" ) ?;
406+ info ! (
407+ "moved crash dump {} to output directory: {}" ,
408+ next. path( ) . display( ) ,
409+ dest_path. display( )
410+ ) ;
411+ found_dump = true ;
412+ break ;
413+ }
406414 }
407- }
408415
409- if !found_dump {
410- info ! ( "no crash dump found with extension .dmp" ) ;
416+ if !found_dump {
417+ info ! ( "no crash dump found with extension .dmp" ) ;
418+ }
411419 }
412420 }
413421
@@ -425,7 +433,9 @@ where
425433
426434 // output directories (init):
427435 self . config . crashes . init ( ) . await ?;
428- self . config . crashdumps . init ( ) . await ?;
436+ if let Some ( crashdumps) = & self . config . crashdumps {
437+ crashdumps. init ( ) . await ?;
438+ }
429439
430440 Ok ( ( ) )
431441 }
0 commit comments