From 0cafa5c72d9ab9cb934315ec80b49b506d837c71 Mon Sep 17 00:00:00 2001 From: "Dongjia \"toka\" Zhang" Date: Sat, 30 Mar 2024 17:04:28 +0100 Subject: [PATCH] Don't use unwrap() in the crash handler (#1979) * don't * win * fix --------- Co-authored-by: Andrea Fioraldi --- libafl/src/executors/hooks/unix.rs | 32 +++++++++++++++++---------- libafl/src/executors/hooks/windows.rs | 4 ++-- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/libafl/src/executors/hooks/unix.rs b/libafl/src/executors/hooks/unix.rs index 7a4544b82c..2f127ccd80 100644 --- a/libafl/src/executors/hooks/unix.rs +++ b/libafl/src/executors/hooks/unix.rs @@ -204,17 +204,21 @@ pub mod unix_signal_handler { let mut bsod = Vec::new(); { let mut writer = std::io::BufWriter::new(&mut bsod); - writeln!(writer, "input: {:?}", input.generate_name(0)).unwrap(); - libafl_bolts::minibsod::generate_minibsod( + let _ = writeln!(writer, "input: {:?}", input.generate_name(0)); + let bsod = libafl_bolts::minibsod::generate_minibsod( &mut writer, signal, _info, _context.as_deref(), - ) - .unwrap(); - writer.flush().unwrap(); + ); + if bsod.is_err() { + log::error!("generate_minibsod failed"); + } + let _ = writer.flush(); + } + if let Ok(r) = std::str::from_utf8(&bsod) { + log::error!("{}", r); } - log::error!("{}", std::str::from_utf8(&bsod).unwrap()); } run_observers_and_save_state::( @@ -241,16 +245,20 @@ pub mod unix_signal_handler { let mut bsod = Vec::new(); { let mut writer = std::io::BufWriter::new(&mut bsod); - libafl_bolts::minibsod::generate_minibsod( + let bsod = libafl_bolts::minibsod::generate_minibsod( &mut writer, signal, _info, _context.as_deref(), - ) - .unwrap(); - writer.flush().unwrap(); + ); + if bsod.is_err() { + log::error!("generate_minibsod failed"); + } + let _ = writer.flush(); + } + if let Ok(r) = std::str::from_utf8(&bsod) { + log::error!("{}", r); } - log::error!("{}", std::str::from_utf8(&bsod).unwrap()); } } @@ -258,7 +266,7 @@ pub mod unix_signal_handler { log::error!("Type QUIT to restart the child"); let mut line = String::new(); while line.trim() != "QUIT" { - std::io::stdin().read_line(&mut line).unwrap(); + let _ = std::io::stdin().read_line(&mut line); } } diff --git a/libafl/src/executors/hooks/windows.rs b/libafl/src/executors/hooks/windows.rs index baf740c5b1..d5e7efadd5 100644 --- a/libafl/src/executors/hooks/windows.rs +++ b/libafl/src/executors/hooks/windows.rs @@ -64,7 +64,7 @@ pub mod windows_asan_handler { log::error!("Type QUIT to restart the child"); let mut line = String::new(); while line.trim() != "QUIT" { - std::io::stdin().read_line(&mut line).unwrap(); + let _ = std::io::stdin().read_line(&mut line); } } @@ -370,7 +370,7 @@ pub mod windows_exception_handler { log::error!("Type QUIT to restart the child"); let mut line = String::new(); while line.trim() != "QUIT" { - std::io::stdin().read_line(&mut line).unwrap(); + let _ = std::io::stdin().read_line(&mut line); } }