Skip to content

Commit e370e2f

Browse files
Code Cleanup of #2422 (#2534)
* code cleanup * removing another unnecessary borrow * cleaning up the cleanup
1 parent 2c676f0 commit e370e2f

File tree

3 files changed

+18
-28
lines changed

3 files changed

+18
-28
lines changed

fuzzers/baby/baby_fuzzer_custom_input/src/input.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ impl CustomInput {
4343
(&mut self.byte_array).into()
4444
}
4545

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

@@ -54,7 +54,7 @@ impl CustomInput {
5454
}
5555

5656
/// Returns an immutable reference to the optional byte array
57-
pub fn optional_byte_array_optional<'a>(&'a self) -> Option<&'a [u8]> {
57+
pub fn optional_byte_array(&self) -> Option<&[u8]> {
5858
self.optional_byte_array.as_deref()
5959
}
6060
}

fuzzers/baby/baby_fuzzer_custom_input/src/main.rs

+11-23
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,9 @@ use libafl_bolts::{
2929
};
3030
#[cfg(not(feature = "simple_interface"))]
3131
use {
32-
libafl::{
33-
inputs::MutVecInput,
34-
mutators::{
35-
havoc_mutations::{havoc_crossover_with_corpus_mapper, havoc_mutations_no_crossover},
36-
mapping::{ToMappedInputFunctionMappingMutatorMapper, ToOptionMappingMutatorMapper},
37-
},
32+
libafl::mutators::{
33+
havoc_mutations::{havoc_crossover_with_corpus_mapper, havoc_mutations_no_crossover},
34+
mapping::{ToMappedInputFunctionMappingMutatorMapper, ToOptionMappingMutatorMapper},
3835
},
3936
libafl_bolts::tuples::Map,
4037
};
@@ -140,39 +137,30 @@ pub fn main() {
140137
#[cfg(feature = "simple_interface")]
141138
let (mapped_mutators, optional_mapped_mutators) = {
142139
// Creating mutators that will operate on input.byte_array
143-
let mapped_mutators = mapped_havoc_mutations(
144-
CustomInput::byte_array_mut,
145-
CustomInput::byte_array_optional,
146-
);
140+
let mapped_mutators =
141+
mapped_havoc_mutations(CustomInput::byte_array_mut, CustomInput::byte_array);
147142

148143
// Creating mutators that will operate on input.optional_byte_array
149144
let optional_mapped_mutators = optional_mapped_havoc_mutations(
150145
CustomInput::optional_byte_array_mut,
151-
CustomInput::optional_byte_array_optional,
146+
CustomInput::optional_byte_array,
152147
);
153148
(mapped_mutators, optional_mapped_mutators)
154149
};
155150

156151
#[cfg(not(feature = "simple_interface"))]
157152
let (mapped_mutators, optional_mapped_mutators) = {
158153
// Creating mutators that will operate on input.byte_array
159-
// For now, due to a limitation in lifetime management (see the MappedInput trait),
160-
// the types have to be partially specified
161154
let mapped_mutators = havoc_mutations_no_crossover()
162-
.merge(havoc_crossover_with_corpus_mapper(
163-
&CustomInput::byte_array_optional,
164-
))
165-
.map(ToMappedInputFunctionMappingMutatorMapper::<
166-
_,
167-
MutVecInput<'_>,
168-
>::new(CustomInput::byte_array_mut));
155+
.merge(havoc_crossover_with_corpus_mapper(CustomInput::byte_array))
156+
.map(ToMappedInputFunctionMappingMutatorMapper::new(
157+
CustomInput::byte_array_mut,
158+
));
169159

170160
// Creating mutators that will operate on input.optional_byte_array
171-
// For now, due to a limitation in lifetime management (see the MappedInput trait),
172-
// the types have to be partially specified
173161
let optional_mapped_mutators = havoc_mutations_no_crossover()
174162
.merge(havoc_crossover_with_corpus_mapper(
175-
&CustomInput::optional_byte_array_optional,
163+
CustomInput::optional_byte_array,
176164
))
177165
.map(ToOptionMappingMutatorMapper)
178166
.map(ToMappedInputFunctionMappingMutatorMapper::new(

libafl/src/mutators/havoc_mutations.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,11 @@ pub fn havoc_crossover<I>() -> HavocCrossoverType<I> {
201201
}
202202

203203
/// Get the mutations that compose the Havoc mutator's crossover strategy with custom corpus extraction logic
204-
pub fn havoc_crossover_with_corpus_mapper<F, O>(input_mapper: F) -> MappedHavocCrossoverType<F, O>
204+
pub fn havoc_crossover_with_corpus_mapper<F, IO, O>(
205+
input_mapper: F,
206+
) -> MappedHavocCrossoverType<F, O>
205207
where
206-
F: Clone,
208+
F: Clone + Fn(IO) -> O,
207209
{
208210
tuple_list!(
209211
MappedCrossoverInsertMutator::new(input_mapper.clone()),

0 commit comments

Comments
 (0)