Skip to content

Commit defb475

Browse files
authored
Fix EdgeCoverageModuleBuilder (#2931)
1 parent a27da1b commit defb475

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

fuzzers/binary_only/fuzzbench_fork_qemu/Makefile.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ windows_alias = "unsupported"
9090
script_runner = "@shell"
9191
script = '''
9292
timeout 15s ${TARGET_DIR}/${PROFILE_DIR}/fuzzbench_fork_qemu ${PROJECT_DIR}/harness -- --libafl-in ${PROJECT_DIR}/../../inprocess/libfuzzer_libpng/corpus --libafl-out ${PROJECT_DIR}/out ${PROJECT_DIR}/harness | tee fuzz_stdout.log
93-
if grep -qa "objectives: 1" fuzz_stdout.log; then
93+
if grep -qa "corpus: 5" fuzz_stdout.log; then
9494
echo "Fuzzer is working"
9595
else
9696
echo "Fuzzer does not generate any testcases or any crashes"

fuzzers/binary_only/fuzzbench_fork_qemu/src/fuzzer.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use libafl_qemu::{
5656
Emulator, GuestReg, MmapPerms, QemuExitError, QemuExitReason, QemuForkExecutor,
5757
QemuShutdownCause, Regs,
5858
};
59-
use libafl_targets::{EDGES_MAP_DEFAULT_SIZE, EDGES_MAP_PTR};
59+
use libafl_targets::EDGES_MAP_DEFAULT_SIZE;
6060
#[cfg(unix)]
6161
use nix::unistd::dup;
6262

@@ -155,7 +155,6 @@ fn fuzz(
155155

156156
let mut edges_shmem = shmem_provider.new_shmem(EDGES_MAP_DEFAULT_SIZE).unwrap();
157157
let edges = edges_shmem.as_slice_mut();
158-
unsafe { EDGES_MAP_PTR = edges.as_mut_ptr() };
159158

160159
// Create an observation channel using the coverage map
161160
let mut edges_observer = unsafe {

libafl_qemu/src/modules/edges/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,20 @@ impl<AF, PF, V, const IS_INITIALIZED: bool, const IS_CONST_MAP: bool, const MAP_
194194
#[must_use]
195195
pub fn const_map_observer<O, const NEW_MAP_SIZE: usize>(
196196
self,
197-
_const_map_observer: &mut O,
197+
map_observer: &mut O,
198198
) -> EdgeCoverageModuleBuilder<AF, PF, V, true, true, NEW_MAP_SIZE>
199199
where
200200
O: ConstLenMapObserver<NEW_MAP_SIZE>,
201201
{
202+
let map_ptr = map_observer.map_slice_mut().as_mut_ptr() as *mut u8;
203+
204+
unsafe {
205+
LIBAFL_QEMU_EDGES_MAP_PTR = map_ptr;
206+
// LIBAFL_QEMU_EDGES_MAP_SIZE_PTR = size_ptr; do i need this ?
207+
LIBAFL_QEMU_EDGES_MAP_ALLOCATED_SIZE = NEW_MAP_SIZE;
208+
LIBAFL_QEMU_EDGES_MAP_MASK_MAX = NEW_MAP_SIZE - 1;
209+
}
210+
202211
EdgeCoverageModuleBuilder::<AF, PF, V, true, true, NEW_MAP_SIZE>::new(
203212
self.variant,
204213
self.address_filter,

0 commit comments

Comments
 (0)