Skip to content

Commit

Permalink
Prefer panic catching strategy over adjusting panic strategy.
Browse files Browse the repository at this point in the history
Fixes #120.
  • Loading branch information
frewsxcv committed Nov 25, 2017
1 parent 2cf8544 commit f99290b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/bin/cargo-afl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ where
"-C llvm-args=-sanitizer-coverage-level=3 \
-C llvm-args=-sanitizer-coverage-trace-pc-guard \
-C passes=sancov \
-C panic=abort \
-l afl-llvm-rt \
-L {}",
dirs::afl_llvm_rt().display()
Expand Down
21 changes: 17 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// See `LICENSE` in this repository.

use std::io::{self, Read};
use std::{panic, process};

/// Utility that reads a `Vec` of bytes from standard input (stdin)
/// and passes it to `closure`. All panics that occur within
Expand All @@ -29,12 +30,18 @@ use std::io::{self, Read};
/// ```
pub fn read_stdio_bytes<F>(closure: F)
where
F: Fn(Vec<u8>),
F: Fn(Vec<u8>) + panic::RefUnwindSafe,
{
let mut input = vec![];
let result = io::stdin().read_to_end(&mut input);
if result.is_ok() {
if result.is_err() {
return;
}
let was_panic = panic::catch_unwind(|| {
closure(input);
});
if was_panic.is_err() {
process::abort();
}
}

Expand All @@ -61,12 +68,18 @@ where
/// ```
pub fn read_stdio_string<F>(closure: F)
where
F: Fn(String),
F: Fn(String) + panic::RefUnwindSafe,
{
let mut input = String::new();
let result = io::stdin().read_to_string(&mut input);
if result.is_ok() {
if result.is_err() {
return;
}
let was_panic = panic::catch_unwind(|| {
closure(input);
});
if was_panic.is_err() {
process::abort();
}
}

Expand Down

0 comments on commit f99290b

Please sign in to comment.