fix hascorpus generic

This commit is contained in:
Andrea Fioraldi 2021-02-11 22:10:20 +01:00
parent 2a937eb88d
commit 9272b8b37b
6 changed files with 36 additions and 18 deletions

View File

@ -25,7 +25,7 @@ where
C: Corpus<I, R>,
I: Input,
R: Rand,
S: HasCorpus<C> + HasMetadata,
S: HasCorpus<C, I, R> + HasMetadata,
{
/// Mutate a given input
fn mutate(

View File

@ -70,7 +70,7 @@ where
C: Corpus<I, R>,
I: Input,
R: Rand,
S: HasCorpus<C> + HasMetadata,
S: HasCorpus<C, I, R> + HasMetadata,
{
/// Get a mutation by index
fn mutation_by_idx(&self, index: usize) -> MutationFunction<I, Self, R, S>;
@ -684,7 +684,7 @@ where
C: Corpus<I, R>,
I: Input + HasBytesVec,
R: Rand,
S: HasCorpus<C>,
S: HasCorpus<C, I, R>,
{
// We don't want to use the testcase we're already using for splicing
let (other_testcase, idx) = state.corpus().random_entry(rand)?;

View File

@ -16,7 +16,7 @@ where
C: Corpus<I, R>,
I: Input,
R: Rand,
S: HasCorpus<C> + HasMetadata,
S: HasCorpus<C, I, R> + HasMetadata,
{
/// Compute the number of iterations used to apply stacked mutations
#[inline]
@ -55,7 +55,7 @@ where
C: Corpus<I, R>,
I: Input,
R: Rand,
S: HasCorpus<C> + HasMetadata,
S: HasCorpus<C, I, R> + HasMetadata,
{
mutations: Vec<MutationFunction<I, Self, R, S>>,
max_size: usize,
@ -66,7 +66,7 @@ where
C: Corpus<I, R>,
I: Input,
R: Rand,
S: HasCorpus<C> + HasMetadata,
S: HasCorpus<C, I, R> + HasMetadata,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
@ -84,7 +84,7 @@ where
C: Corpus<I, R>,
I: Input,
R: Rand,
S: HasCorpus<C> + HasMetadata,
S: HasCorpus<C, I, R> + HasMetadata,
{
fn mutate(
&mut self,
@ -102,7 +102,7 @@ where
C: Corpus<I, R>,
I: Input,
R: Rand,
S: HasCorpus<C> + HasMetadata,
S: HasCorpus<C, I, R> + HasMetadata,
{
#[inline]
fn mutation_by_idx(&self, index: usize) -> MutationFunction<I, Self, R, S> {
@ -125,7 +125,7 @@ where
C: Corpus<I, R>,
I: Input,
R: Rand,
S: HasCorpus<C> + HasMetadata,
S: HasCorpus<C, I, R> + HasMetadata,
{
// Just use the default methods
}
@ -135,7 +135,7 @@ where
C: Corpus<I, R>,
I: Input,
R: Rand,
S: HasCorpus<C> + HasMetadata,
S: HasCorpus<C, I, R> + HasMetadata,
{
#[inline]
fn max_size(&self) -> usize {
@ -153,7 +153,7 @@ where
C: Corpus<I, R>,
I: Input,
R: Rand,
S: HasCorpus<C> + HasMetadata,
S: HasCorpus<C, I, R> + HasMetadata,
{
/// Create a new StdScheduledMutator instance without mutations and corpus
pub fn new() -> Self {
@ -180,7 +180,7 @@ where
C: Corpus<I, R>,
I: Input + HasBytesVec,
R: Rand,
S: HasCorpus<C> + HasMetadata,
S: HasCorpus<C, I, R> + HasMetadata,
{
scheduled: SM,
phantom: PhantomData<(C, I, R, S)>,
@ -192,7 +192,7 @@ where
C: Corpus<I, R>,
I: Input + HasBytesVec,
R: Rand,
S: HasCorpus<C> + HasMetadata,
S: HasCorpus<C, I, R> + HasMetadata,
{
/// Mutate bytes
fn mutate(
@ -234,7 +234,7 @@ where
C: Corpus<I, R>,
I: Input + HasBytesVec,
R: Rand,
S: HasCorpus<C> + HasMetadata,
S: HasCorpus<C, I, R> + HasMetadata,
{
#[inline]
fn max_size(&self) -> usize {
@ -253,7 +253,7 @@ where
C: Corpus<I, R>,
I: Input + HasBytesVec,
R: Rand,
S: HasCorpus<C> + HasMetadata,
S: HasCorpus<C, I, R> + HasMetadata,
{
/// Create a new HavocBytesMutator instance given a ScheduledMutator to wrap
pub fn new(mut scheduled: SM) -> Self {
@ -271,7 +271,7 @@ where
C: Corpus<I, R>,
I: Input + HasBytesVec,
R: Rand,
S: HasCorpus<C> + HasMetadata,
S: HasCorpus<C, I, R> + HasMetadata,
{
/// Create a new HavocBytesMutator instance wrapping StdScheduledMutator
pub fn new_default() -> Self {

View File

@ -25,7 +25,12 @@ use crate::{
use crate::inputs::bytes::BytesInput;
/// Trait for elements offering a corpus
pub trait HasCorpus<C> {
pub trait HasCorpus<C, I, R>
where
C: Corpus<I, R>,
I: Input,
R: Rand,
{
/// The testcase corpus
fn corpus(&self) -> &C;
/// The testcase corpus (mut)
@ -147,7 +152,7 @@ where
}
}
impl<C, FT, I, R> HasCorpus<C> for State<C, FT, I, R>
impl<C, FT, I, R> HasCorpus<C, I, R> for State<C, FT, I, R>
where
C: Corpus<I, R>,
I: Input,

View File

@ -26,6 +26,7 @@ clap = "2.32.0"
serde = { version = "1.0", default-features = false, features = ["alloc"] }
postcard = { version = "0.5.1", features = ["alloc"] }
afl = { path = "../../afl/" }
# libc = "0.2"
[[bin]]
name = "libfuzzer"

View File

@ -4,6 +4,8 @@
#[macro_use]
extern crate clap;
// extern crate libc;
use clap::{App, Arg};
use std::{env, path::PathBuf};
@ -162,6 +164,16 @@ fn fuzz(input: Option<Vec<PathBuf>>, broker_port: u16) -> Result<(), AflError> {
println!("Warning: LLVMFuzzerInitialize failed with -1")
}
}
/*
// TODO close fds in a rusty way
unsafe {
let null_fname = std::ffi::CString::new("/dev/null").unwrap();
let null_file = libc::open(null_fname.as_ptr(), libc::O_RDWR);
libc::dup2(null_file, 1);
libc::dup2(null_file, 2);
}
*/
// in case the corpus is empty (on first run), reset
if state.corpus().count() < 1 {