Skip to content

Commit

Permalink
LibAFL_QEMU: Don't require extra_tokens. (#2576)
Browse files Browse the repository at this point in the history
Co-authored-by: Romain Malmain <[email protected]>
  • Loading branch information
domenukk and rmalmain authored Oct 7, 2024
1 parent 1fbb18c commit 27677a6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
31 changes: 17 additions & 14 deletions fuzzers/binary_only/qemu_launcher/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ impl<'a> Client<'a> {
}
});

let extra_tokens = injection_module.as_ref().map(|h| h.tokens.clone());

qemu.entry_break(start_pc);

let ret_addr: GuestAddr = qemu
Expand All @@ -169,7 +167,12 @@ impl<'a> Client<'a> {
.address_filter(self.coverage_filter(&qemu)?)
.build();

let instance = Instance::builder()
let extra_tokens = injection_module
.as_ref()
.map(|h| h.tokens.clone())
.unwrap_or_default();

let instance_builder = Instance::builder()
.options(self.options)
.qemu(&qemu)
.mgr(mgr)
Expand All @@ -178,7 +181,7 @@ impl<'a> Client<'a> {

if is_asan && is_cmplog {
if let Some(injection_module) = injection_module {
instance.build().run(
instance_builder.build().run(
tuple_list!(
edge_coverage_module,
CmpLogModule::default(),
Expand All @@ -188,7 +191,7 @@ impl<'a> Client<'a> {
state,
)
} else {
instance.build().run(
instance_builder.build().run(
tuple_list!(
edge_coverage_module,
CmpLogModule::default(),
Expand All @@ -199,7 +202,7 @@ impl<'a> Client<'a> {
}
} else if is_asan_guest && is_cmplog {
if let Some(injection_module) = injection_module {
instance.build().run(
instance_builder.build().run(
tuple_list!(
edge_coverage_module,
CmpLogModule::default(),
Expand All @@ -209,7 +212,7 @@ impl<'a> Client<'a> {
state,
)
} else {
instance.build().run(
instance_builder.build().run(
tuple_list!(
edge_coverage_module,
CmpLogModule::default(),
Expand All @@ -220,7 +223,7 @@ impl<'a> Client<'a> {
}
} else if is_asan {
if let Some(injection_module) = injection_module {
instance.build().run(
instance_builder.build().run(
tuple_list!(
edge_coverage_module,
AsanModule::default(asan.take().unwrap()),
Expand All @@ -229,7 +232,7 @@ impl<'a> Client<'a> {
state,
)
} else {
instance.build().run(
instance_builder.build().run(
tuple_list!(
edge_coverage_module,
AsanModule::default(asan.take().unwrap()),
Expand All @@ -242,10 +245,10 @@ impl<'a> Client<'a> {
edge_coverage_module,
AsanGuestModule::default(&qemu, asan_lib.take().unwrap())
);
instance.build().run(modules, state)
instance_builder.build().run(modules, state)
} else if is_cmplog {
if let Some(injection_module) = injection_module {
instance.build().run(
instance_builder.build().run(
tuple_list!(
edge_coverage_module,
CmpLogModule::default(),
Expand All @@ -254,17 +257,17 @@ impl<'a> Client<'a> {
state,
)
} else {
instance.build().run(
instance_builder.build().run(
tuple_list!(edge_coverage_module, CmpLogModule::default()),
state,
)
}
} else if let Some(injection_module) = injection_module {
instance
instance_builder
.build()
.run(tuple_list!(edge_coverage_module, injection_module), state)
} else {
instance
instance_builder
.build()
.run(tuple_list!(edge_coverage_module), state)
}
Expand Down
11 changes: 5 additions & 6 deletions fuzzers/binary_only/qemu_launcher/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ pub struct Instance<'a, M: Monitor> {
qemu: &'a Qemu,
mgr: ClientMgr<M>,
core_id: CoreId,
extra_tokens: Option<Vec<String>>,
#[builder(default)]
extra_tokens: Vec<String>,
#[builder(default=PhantomData)]
phantom: PhantomData<M>,
}
Expand Down Expand Up @@ -134,11 +135,9 @@ impl<'a, M: Monitor> Instance<'a, M> {

let mut tokens = Tokens::new();

if let Some(extra_tokens) = &self.extra_tokens {
for token in extra_tokens {
let bytes = token.as_bytes().to_vec();
let _ = tokens.add_token(&bytes);
}
for token in &self.extra_tokens {
let bytes = token.as_bytes().to_vec();
let _ = tokens.add_token(&bytes);
}

if let Some(tokenfile) = &self.options.tokens {
Expand Down
2 changes: 2 additions & 0 deletions libafl_qemu/src/modules/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ pub struct EdgeCoverageModuleBuilder<AF, PF, V> {
pub struct EdgeCoverageModule<AF, PF, V> {
variant: V,
address_filter: AF,
// we only use it in system mode at the moment.
#[cfg_attr(not(emulation_mode = "systemmode"), allow(dead_code))]
page_filter: PF,
use_hitcounts: bool,
use_jit: bool,
Expand Down

0 comments on commit 27677a6

Please sign in to comment.