From 5c60ae15bea6669682b3c6d44927cb5e3d1b3260 Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Wed, 27 Jun 2018 16:09:10 +0300 Subject: [PATCH] Add Address Sanitizer exceptions to fuzzing targets, see #80 and https://github.com/rust-lang/rust/issues/41807 --- fuzz/fuzz_targets/fuzz_target_1.rs | 10 ++++++++++ png-afl/src/main.rs | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/fuzz/fuzz_targets/fuzz_target_1.rs b/fuzz/fuzz_targets/fuzz_target_1.rs index afcbf19e..db1a45d4 100644 --- a/fuzz/fuzz_targets/fuzz_target_1.rs +++ b/fuzz/fuzz_targets/fuzz_target_1.rs @@ -2,6 +2,16 @@ #[macro_use] extern crate libfuzzer_sys; extern crate png; +// allocator_may_return_null=1 prevents crash on allocating huge amounts of memory, see #80 +// detect_odr_violation=0 is for https://github.com/rust-lang/rust/issues/41807 +const ASAN_DEFAULT_OPTIONS: &'static [u8] = b"allocator_may_return_null=1,detect_odr_violation=0\0"; + +#[no_mangle] +pub extern "C" fn __asan_default_options() -> *const u8 { + ASAN_DEFAULT_OPTIONS as *const [u8] as *const u8 +} + + #[inline(always)] fn png_decode(data: &[u8]) -> Result<(png::OutputInfo, Vec), ()> { let decoder = png::Decoder::new(data); diff --git a/png-afl/src/main.rs b/png-afl/src/main.rs index 5010364c..927ffaff 100644 --- a/png-afl/src/main.rs +++ b/png-afl/src/main.rs @@ -1,7 +1,9 @@ extern crate afl; extern crate png; -const ASAN_DEFAULT_OPTIONS: &'static [u8] = b"detect_odr_violation=1\0"; +// allocator_may_return_null=1 prevents crash on allocating huge amounts of memory, see #80 +// detect_odr_violation=0 is for https://github.com/rust-lang/rust/issues/41807 +const ASAN_DEFAULT_OPTIONS: &'static [u8] = b"allocator_may_return_null=1,detect_odr_violation=0\0"; #[no_mangle] pub extern "C" fn __asan_default_options() -> *const u8 {