Skip to content

Code Cleanup #2534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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