Code Cleanup of #2422 (#2534)

* code cleanup

* removing another unnecessary borrow

* cleaning up the cleanup
This commit is contained in:
Valentin Huber 2024-09-20 17:39:09 +02:00 committed by GitHub
parent 2c676f0352
commit e370e2f852
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 28 deletions

View File

@ -43,8 +43,8 @@ impl CustomInput {
(&mut self.byte_array).into() (&mut self.byte_array).into()
} }
/// Returns an immutable reference to the byte array wrapped in [`Some`] /// Returns an immutable reference to the byte array
pub fn byte_array_optional<'a>(&'a self) -> &'a [u8] { pub fn byte_array(&self) -> &[u8] {
&self.byte_array &self.byte_array
} }
@ -54,7 +54,7 @@ impl CustomInput {
} }
/// Returns an immutable reference to the optional byte array /// 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() self.optional_byte_array.as_deref()
} }
} }

View File

@ -29,13 +29,10 @@ use libafl_bolts::{
}; };
#[cfg(not(feature = "simple_interface"))] #[cfg(not(feature = "simple_interface"))]
use { use {
libafl::{ libafl::mutators::{
inputs::MutVecInput,
mutators::{
havoc_mutations::{havoc_crossover_with_corpus_mapper, havoc_mutations_no_crossover}, havoc_mutations::{havoc_crossover_with_corpus_mapper, havoc_mutations_no_crossover},
mapping::{ToMappedInputFunctionMappingMutatorMapper, ToOptionMappingMutatorMapper}, mapping::{ToMappedInputFunctionMappingMutatorMapper, ToOptionMappingMutatorMapper},
}, },
},
libafl_bolts::tuples::Map, libafl_bolts::tuples::Map,
}; };
@ -140,15 +137,13 @@ pub fn main() {
#[cfg(feature = "simple_interface")] #[cfg(feature = "simple_interface")]
let (mapped_mutators, optional_mapped_mutators) = { let (mapped_mutators, optional_mapped_mutators) = {
// Creating mutators that will operate on input.byte_array // Creating mutators that will operate on input.byte_array
let mapped_mutators = mapped_havoc_mutations( let mapped_mutators =
CustomInput::byte_array_mut, mapped_havoc_mutations(CustomInput::byte_array_mut, CustomInput::byte_array);
CustomInput::byte_array_optional,
);
// Creating mutators that will operate on input.optional_byte_array // Creating mutators that will operate on input.optional_byte_array
let optional_mapped_mutators = optional_mapped_havoc_mutations( let optional_mapped_mutators = optional_mapped_havoc_mutations(
CustomInput::optional_byte_array_mut, CustomInput::optional_byte_array_mut,
CustomInput::optional_byte_array_optional, CustomInput::optional_byte_array,
); );
(mapped_mutators, optional_mapped_mutators) (mapped_mutators, optional_mapped_mutators)
}; };
@ -156,23 +151,16 @@ pub fn main() {
#[cfg(not(feature = "simple_interface"))] #[cfg(not(feature = "simple_interface"))]
let (mapped_mutators, optional_mapped_mutators) = { let (mapped_mutators, optional_mapped_mutators) = {
// Creating mutators that will operate on input.byte_array // 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() let mapped_mutators = havoc_mutations_no_crossover()
.merge(havoc_crossover_with_corpus_mapper( .merge(havoc_crossover_with_corpus_mapper(CustomInput::byte_array))
&CustomInput::byte_array_optional, .map(ToMappedInputFunctionMappingMutatorMapper::new(
)) CustomInput::byte_array_mut,
.map(ToMappedInputFunctionMappingMutatorMapper::< ));
_,
MutVecInput<'_>,
>::new(CustomInput::byte_array_mut));
// Creating mutators that will operate on input.optional_byte_array // 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() let optional_mapped_mutators = havoc_mutations_no_crossover()
.merge(havoc_crossover_with_corpus_mapper( .merge(havoc_crossover_with_corpus_mapper(
&CustomInput::optional_byte_array_optional, CustomInput::optional_byte_array,
)) ))
.map(ToOptionMappingMutatorMapper) .map(ToOptionMappingMutatorMapper)
.map(ToMappedInputFunctionMappingMutatorMapper::new( .map(ToMappedInputFunctionMappingMutatorMapper::new(

View File

@ -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 /// 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 where
F: Clone, F: Clone + Fn(IO) -> O,
{ {
tuple_list!( tuple_list!(
MappedCrossoverInsertMutator::new(input_mapper.clone()), MappedCrossoverInsertMutator::new(input_mapper.clone()),