Don't use unwrap() in the crash handler (#1979)

* don't

* win

* fix

---------

Co-authored-by: Andrea Fioraldi <andreafioraldi@gmail.com>
This commit is contained in:
Dongjia "toka" Zhang 2024-03-30 17:04:28 +01:00 committed by GitHub
parent 15aabfe65d
commit 0cafa5c72d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 14 deletions

View File

@ -204,17 +204,21 @@ pub mod unix_signal_handler {
let mut bsod = Vec::new(); let mut bsod = Vec::new();
{ {
let mut writer = std::io::BufWriter::new(&mut bsod); let mut writer = std::io::BufWriter::new(&mut bsod);
writeln!(writer, "input: {:?}", input.generate_name(0)).unwrap(); let _ = writeln!(writer, "input: {:?}", input.generate_name(0));
libafl_bolts::minibsod::generate_minibsod( let bsod = libafl_bolts::minibsod::generate_minibsod(
&mut writer, &mut writer,
signal, signal,
_info, _info,
_context.as_deref(), _context.as_deref(),
) );
.unwrap(); if bsod.is_err() {
writer.flush().unwrap(); 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::<E, EM, OF, Z>( run_observers_and_save_state::<E, EM, OF, Z>(
@ -241,16 +245,20 @@ pub mod unix_signal_handler {
let mut bsod = Vec::new(); let mut bsod = Vec::new();
{ {
let mut writer = std::io::BufWriter::new(&mut bsod); let mut writer = std::io::BufWriter::new(&mut bsod);
libafl_bolts::minibsod::generate_minibsod( let bsod = libafl_bolts::minibsod::generate_minibsod(
&mut writer, &mut writer,
signal, signal,
_info, _info,
_context.as_deref(), _context.as_deref(),
) );
.unwrap(); if bsod.is_err() {
writer.flush().unwrap(); 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"); log::error!("Type QUIT to restart the child");
let mut line = String::new(); let mut line = String::new();
while line.trim() != "QUIT" { while line.trim() != "QUIT" {
std::io::stdin().read_line(&mut line).unwrap(); let _ = std::io::stdin().read_line(&mut line);
} }
} }

View File

@ -64,7 +64,7 @@ pub mod windows_asan_handler {
log::error!("Type QUIT to restart the child"); log::error!("Type QUIT to restart the child");
let mut line = String::new(); let mut line = String::new();
while line.trim() != "QUIT" { 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"); log::error!("Type QUIT to restart the child");
let mut line = String::new(); let mut line = String::new();
while line.trim() != "QUIT" { while line.trim() != "QUIT" {
std::io::stdin().read_line(&mut line).unwrap(); let _ = std::io::stdin().read_line(&mut line);
} }
} }