Skip to content

Commit b47ec90

Browse files
committed
code cleanup
1 parent 3afb25a commit b47ec90

File tree

3 files changed

+18
-24
lines changed

3 files changed

+18
-24
lines changed

fuzzers/baby/baby_fuzzer_custom_input/src/input.rs

Lines changed: 3 additions & 3 deletions
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
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

Lines changed: 11 additions & 19 deletions
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,15 +137,13 @@ 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
};
@@ -159,20 +154,17 @@ pub fn main() {
159154
// For now, due to a limitation in lifetime management (see the MappedInput trait),
160155
// the types have to be partially specified
161156
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));
157+
.merge(havoc_crossover_with_corpus_mapper(CustomInput::byte_array))
158+
.map(ToMappedInputFunctionMappingMutatorMapper::new(
159+
CustomInput::byte_array_mut,
160+
));
169161

170162
// Creating mutators that will operate on input.optional_byte_array
171163
// For now, due to a limitation in lifetime management (see the MappedInput trait),
172164
// the types have to be partially specified
173165
let optional_mapped_mutators = havoc_mutations_no_crossover()
174166
.merge(havoc_crossover_with_corpus_mapper(
175-
&CustomInput::optional_byte_array_optional,
167+
CustomInput::optional_byte_array,
176168
))
177169
.map(ToOptionMappingMutatorMapper)
178170
.map(ToMappedInputFunctionMappingMutatorMapper::new(

libafl/src/mutators/havoc_mutations.rs

Lines changed: 4 additions & 2 deletions
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)