Skip to content

Commit dc2b4d2

Browse files
committed
fuzz: Adjust print and exit options
1 parent 6c8593f commit dc2b4d2

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

fuzz/src/main.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ enum Commands {
8585
fn main() {
8686
let cli_args = Args::parse();
8787

88+
// Check and panic as the fuzzer needs to do.
89+
let fuzz_check =
90+
|buf: &[u8], always_print| match decode_eval_check(&buf, &cli_args, always_print) {
91+
Ok(()) => (),
92+
// Discard decoding errors; we don't want the fuzzer to think this is a failure)
93+
Err(Error::Decode(e)) => println!("decode error: {e} (no panic raised)"),
94+
Err(Error::Check(e)) => panic!("check error: {e}"),
95+
};
96+
8897
if let Some(cmd) = &cli_args.command {
8998
match cmd {
9099
Commands::Check { file } => {
@@ -95,11 +104,7 @@ fn main() {
95104
None => &mut io::stdin(),
96105
};
97106
reader.read_to_end(&mut buf).unwrap();
98-
match decode_eval_check(&buf, &cli_args, false) {
99-
Ok(()) => (),
100-
Err(Error::Decode(e)) => println!("error: {e} (no panic raised)"),
101-
Err(Error::Check(e)) => panic!("check error: {e}"),
102-
}
107+
fuzz_check(&buf, true);
103108
}
104109
Commands::Decode { files } => run_decode_subcmd(files, &cli_args),
105110
Commands::Bruteforce { .. } => exhaustive::run_for_all_floats(&cli_args),
@@ -114,8 +119,7 @@ fn main() {
114119
if true {
115120
// FIXME(eddyb) make the first argument (panic hook choice) a CLI toggle.
116121
afl::fuzz(true, |buf| {
117-
// Discard decoding errors
118-
decode_eval_check(&buf, &cli_args, false).unwrap();
122+
fuzz_check(&buf, false);
119123
});
120124

121125
return;

0 commit comments

Comments
 (0)