From e370e2f852b28aa0c4baedff426005429dbb6c08 Mon Sep 17 00:00:00 2001 From: Valentin Huber Date: Fri, 20 Sep 2024 17:39:09 +0200 Subject: [PATCH] Code Cleanup of #2422 (#2534) * code cleanup * removing another unnecessary borrow * cleaning up the cleanup --- .../baby_fuzzer_custom_input/src/input.rs | 6 ++-- .../baby/baby_fuzzer_custom_input/src/main.rs | 34 ++++++------------- libafl/src/mutators/havoc_mutations.rs | 6 ++-- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/fuzzers/baby/baby_fuzzer_custom_input/src/input.rs b/fuzzers/baby/baby_fuzzer_custom_input/src/input.rs index d6ffe0f477..9a1dc569fa 100644 --- a/fuzzers/baby/baby_fuzzer_custom_input/src/input.rs +++ b/fuzzers/baby/baby_fuzzer_custom_input/src/input.rs @@ -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 } @@ -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() } } diff --git a/fuzzers/baby/baby_fuzzer_custom_input/src/main.rs b/fuzzers/baby/baby_fuzzer_custom_input/src/main.rs index 7e3c83dcea..ec0c63f7d1 100644 --- a/fuzzers/baby/baby_fuzzer_custom_input/src/main.rs +++ b/fuzzers/baby/baby_fuzzer_custom_input/src/main.rs @@ -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, }; @@ -140,15 +137,13 @@ 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) }; @@ -156,23 +151,16 @@ pub fn main() { #[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( diff --git a/libafl/src/mutators/havoc_mutations.rs b/libafl/src/mutators/havoc_mutations.rs index 999794c9c9..91a9b654a0 100644 --- a/libafl/src/mutators/havoc_mutations.rs +++ b/libafl/src/mutators/havoc_mutations.rs @@ -201,9 +201,11 @@ pub fn havoc_crossover() -> HavocCrossoverType { } /// Get the mutations that compose the Havoc mutator's crossover strategy with custom corpus extraction logic -pub fn havoc_crossover_with_corpus_mapper(input_mapper: F) -> MappedHavocCrossoverType +pub fn havoc_crossover_with_corpus_mapper( + input_mapper: F, +) -> MappedHavocCrossoverType where - F: Clone, + F: Clone + Fn(IO) -> O, { tuple_list!( MappedCrossoverInsertMutator::new(input_mapper.clone()),