Skip to content

Commit

Permalink
Code Cleanup of #2422 (#2534)
Browse files Browse the repository at this point in the history
* code cleanup

* removing another unnecessary borrow

* cleaning up the cleanup
  • Loading branch information
riesentoaster authored Sep 20, 2024
1 parent 2c676f0 commit e370e2f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
6 changes: 3 additions & 3 deletions fuzzers/baby/baby_fuzzer_custom_input/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ impl CustomInput {
(&mut self.byte_array).into()
}

/// Returns an immutable reference to the byte array wrapped in [`Some`]
pub fn byte_array_optional<'a>(&'a self) -> &'a [u8] {
/// Returns an immutable reference to the byte array
pub fn byte_array(&self) -> &[u8] {
&self.byte_array
}

Expand All @@ -54,7 +54,7 @@ impl CustomInput {
}

/// Returns an immutable reference to the optional byte array
pub fn optional_byte_array_optional<'a>(&'a self) -> Option<&'a [u8]> {
pub fn optional_byte_array(&self) -> Option<&[u8]> {
self.optional_byte_array.as_deref()
}
}
Expand Down
34 changes: 11 additions & 23 deletions fuzzers/baby/baby_fuzzer_custom_input/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ use libafl_bolts::{
};
#[cfg(not(feature = "simple_interface"))]
use {
libafl::{
inputs::MutVecInput,
mutators::{
havoc_mutations::{havoc_crossover_with_corpus_mapper, havoc_mutations_no_crossover},
mapping::{ToMappedInputFunctionMappingMutatorMapper, ToOptionMappingMutatorMapper},
},
libafl::mutators::{
havoc_mutations::{havoc_crossover_with_corpus_mapper, havoc_mutations_no_crossover},
mapping::{ToMappedInputFunctionMappingMutatorMapper, ToOptionMappingMutatorMapper},
},
libafl_bolts::tuples::Map,
};
Expand Down Expand Up @@ -140,39 +137,30 @@ pub fn main() {
#[cfg(feature = "simple_interface")]
let (mapped_mutators, optional_mapped_mutators) = {
// Creating mutators that will operate on input.byte_array
let mapped_mutators = mapped_havoc_mutations(
CustomInput::byte_array_mut,
CustomInput::byte_array_optional,
);
let mapped_mutators =
mapped_havoc_mutations(CustomInput::byte_array_mut, CustomInput::byte_array);

// Creating mutators that will operate on input.optional_byte_array
let optional_mapped_mutators = optional_mapped_havoc_mutations(
CustomInput::optional_byte_array_mut,
CustomInput::optional_byte_array_optional,
CustomInput::optional_byte_array,
);
(mapped_mutators, optional_mapped_mutators)
};

#[cfg(not(feature = "simple_interface"))]
let (mapped_mutators, optional_mapped_mutators) = {
// Creating mutators that will operate on input.byte_array
// For now, due to a limitation in lifetime management (see the MappedInput trait),
// the types have to be partially specified
let mapped_mutators = havoc_mutations_no_crossover()
.merge(havoc_crossover_with_corpus_mapper(
&CustomInput::byte_array_optional,
))
.map(ToMappedInputFunctionMappingMutatorMapper::<
_,
MutVecInput<'_>,
>::new(CustomInput::byte_array_mut));
.merge(havoc_crossover_with_corpus_mapper(CustomInput::byte_array))
.map(ToMappedInputFunctionMappingMutatorMapper::new(
CustomInput::byte_array_mut,
));

// Creating mutators that will operate on input.optional_byte_array
// For now, due to a limitation in lifetime management (see the MappedInput trait),
// the types have to be partially specified
let optional_mapped_mutators = havoc_mutations_no_crossover()
.merge(havoc_crossover_with_corpus_mapper(
&CustomInput::optional_byte_array_optional,
CustomInput::optional_byte_array,
))
.map(ToOptionMappingMutatorMapper)
.map(ToMappedInputFunctionMappingMutatorMapper::new(
Expand Down
6 changes: 4 additions & 2 deletions libafl/src/mutators/havoc_mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,11 @@ pub fn havoc_crossover<I>() -> HavocCrossoverType<I> {
}

/// Get the mutations that compose the Havoc mutator's crossover strategy with custom corpus extraction logic
pub fn havoc_crossover_with_corpus_mapper<F, O>(input_mapper: F) -> MappedHavocCrossoverType<F, O>
pub fn havoc_crossover_with_corpus_mapper<F, IO, O>(
input_mapper: F,
) -> MappedHavocCrossoverType<F, O>
where
F: Clone,
F: Clone + Fn(IO) -> O,
{
tuple_list!(
MappedCrossoverInsertMutator::new(input_mapper.clone()),
Expand Down

0 comments on commit e370e2f

Please sign in to comment.