Skip to content

Instantly share code, notes, and snippets.

@Shnatsel
Last active May 19, 2019 22:07
Show Gist options
  • Save Shnatsel/4a907d44d6429de93d63d6e7c4d1361e to your computer and use it in GitHub Desktop.
Save Shnatsel/4a907d44d6429de93d63d6e7c4d1361e to your computer and use it in GitHub Desktop.
quick'n'dirty fuzz target for Rust str::repeat()
extern crate rand;
extern crate quickcheck;
use std::io::prelude::*;
use quickcheck::{Arbitrary};
// suppress ASAN false positives
const ASAN_DEFAULT_OPTIONS: &'static [u8] = b"allocator_may_return_null=1,detect_odr_violation=1\0";
#[no_mangle]
pub extern "C" fn __asan_default_options() -> *const u8 {
ASAN_DEFAULT_OPTIONS as *const [u8] as *const u8
}
fn main() -> std::result::Result<(), std::io::Error> {
// read fuzzer input from stdin
let mut raw_input = vec![];
std::io::stdin().read_to_end(&mut raw_input)?;
// input preparation for QuickCheck, not specific to the fuzzed function
let input_cursor = std::io::Cursor::new(raw_input);
let read_rng = rand::rngs::adapter::ReadRng::new(input_cursor);
let mut read_rng = quickcheck::StdGen::new(read_rng, std::usize::MAX);
// create input data for specific function from random bytes
let fuzz_self = std::string::String::arbitrary(&mut read_rng);
let fuzz_argument_1 = usize::arbitrary(&mut read_rng);
// invoke function
fuzz_self.repeat(fuzz_argument_1);
Ok(())
}
@Shnatsel
Copy link
Author

This file is dual-licensed under MIT and Apache 2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment