Skip to content

Commit

Permalink
mas mas mas
Browse files Browse the repository at this point in the history
  • Loading branch information
domenukk committed Nov 7, 2024
1 parent 9d7dcd6 commit 4743fbe
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion fuzzers/binary_only/fuzzbench_qemu/src/fuzzer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A singlethreaded QEMU fuzzer that can auto-restart.
use core::{cell::RefCell, ptr::time::Duration};
use core::{cell::RefCell, time::Duration};
#[cfg(unix)]
use std::os::unix::io::{AsRawFd, FromRawFd};
use std::{
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/binary_only/tinyinst_simple/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{path::PathBuf, ptr::time::Duration};
use std::{path::PathBuf, time::Duration};

use libafl::{
corpus::{CachedOnDiskCorpus, Corpus, OnDiskCorpus, Testcase},
Expand Down
7 changes: 4 additions & 3 deletions libafl/src/common/nautilus/regex_mutator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fn append_unicode_range<R: Rand>(
cls: ClassUnicodeRange,
) {
let mut chr_a_buf = [0; 4];
#[allow(clippy::similar_names)]
let mut chr_b_buf = [0; 4];
cls.start().encode_utf8(&mut chr_a_buf);
cls.end().encode_utf8(&mut chr_b_buf);
Expand Down Expand Up @@ -129,10 +130,10 @@ pub fn generate<R: Rand>(rand: &mut R, hir: &Hir) -> Vec<u8> {
HirKind::Empty => {}
HirKind::Literal(lit) => append_lit(&mut res, lit),
HirKind::Class(cls) => append_class(rand, &mut res, &mut scr, cls),
HirKind::Repetition(rep) => {
let num = get_repetitions(rand, rep.min, rep.max, &mut scr);
HirKind::Repetition(repetition) => {
let num = get_repetitions(rand, repetition.min, repetition.max, &mut scr);
for _ in 0..num {
stack.push(&rep.sub);
stack.push(&repetition.sub);
}
}
HirKind::Capture(grp) => stack.push(&grp.sub),
Expand Down
1 change: 0 additions & 1 deletion libafl/src/events/tcp.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! TCP-backed event manager for scalable multi-processed fuzzing
use alloc::{boxed::Box, vec::Vec};
#[cfg(all(unix, feature = "std", not(miri)))]
use core::{
marker::PhantomData,
num::NonZeroUsize,
Expand Down
1 change: 1 addition & 0 deletions libafl/src/stages/afl_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ where
} else {
0
};
#[allow(clippy::similar_names)]
let stats = AFLFuzzerStats {
start_time: self.start_time,
last_update: self.last_report_time.as_secs(),
Expand Down
4 changes: 4 additions & 0 deletions libafl/src/stages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ where
}
Some(idx) if idx == StageId(Self::LEN) => {
// perform the stage, but don't set it

#[allow(clippy::similar_names)]
let stage = &mut self.0;

stage.perform_restartable(fuzzer, executor, state, manager)?;
Expand All @@ -218,6 +220,7 @@ where
_ => {
state.set_current_stage_id(StageId(Self::LEN))?;

#[allow(clippy::similar_names)]
let stage = &mut self.0;
stage.perform_restartable(fuzzer, executor, state, manager)?;

Expand Down Expand Up @@ -820,6 +823,7 @@ mod test {
}
}

#[allow(clippy::similar_names)]
let mut state = StdState::nop()?;
let stage = StageWithOneTry;

Expand Down
4 changes: 2 additions & 2 deletions libafl_libfuzzer/runtime/src/corpus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ where
Ok(())
}
#[inline]
fn _get<'a>(
fn _get(
&'a self,
id: CorpusId,
corpus: &'a TestcaseStorageMap<I>,
corpus: &TestcaseStorageMap<I>,
) -> Result<&RefCell<Testcase<I>>, Error> {
self.touch(id, corpus)?;
corpus.map.get(&id).map(|item| &item.testcase).ok_or_else(|| Error::illegal_state("Nonexistent corpus entry {id} requested (present in loaded entries, but not the mapping?)"))
Expand Down
2 changes: 1 addition & 1 deletion libafl_libfuzzer/runtime/src/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
fs::{rename, File},
io::Write,
os::fd::{AsRawFd, FromRawFd},
ptr::time::{SystemTime, UNIX_EPOCH},
time::{SystemTime, UNIX_EPOCH},
};

use libafl::{
Expand Down
4 changes: 3 additions & 1 deletion libafl_qemu/src/emu/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ where
unsafe {
let emulator_modules = EmulatorModules::<ET, S>::emulator_modules_mut().unwrap();

for crash_hook in &mut (*&raw mut emulator_modules.hooks.crash_hooks) {
let crash_hooks_ptr = &raw mut emulator_modules.hooks.crash_hooks;

for crash_hook in &mut (*crash_hooks_ptr) {
match crash_hook {
HookRepr::Function(ptr) => {
let func: CrashHookFn<ET, S> = transmute(*ptr);
Expand Down
27 changes: 12 additions & 15 deletions libafl_qemu/src/modules/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,17 +547,19 @@ impl FullBacktraceCollector {
/// # Safety
/// This accesses the global [`CALLSTACKS`] variable and may not be called concurrently.
pub unsafe fn new() -> Self {
unsafe { (*&raw mut CALLSTACKS) = Some(ThreadLocal::new()) };
Self {}
let callstacks_ptr = &raw mut CALLSTACKS;
unsafe { (*callstacks_ptr) = Some(ThreadLocal::new()) };
Self
}

pub fn reset(&mut self) {
// # Safety
// This accesses the global [`CALLSTACKS`] variable.
// While it is racey, it might be fine if multiple clear the vecs concurrently.
// TODO: This should probably be rewritten in a safer way.
let callstacks_ptr = &raw mut CALLSTACKS;
unsafe {
for tls in (*&raw mut CALLSTACKS).as_mut().unwrap().iter_mut() {
for tls in (*callstacks_ptr).as_mut().unwrap().iter_mut() {
(*tls.get()).clear();
}
}
Expand All @@ -567,8 +569,9 @@ impl FullBacktraceCollector {
// # Safety
// This accesses the global [`CALLSTACKS`] variable.
// However, the actual variable access is behind a `ThreadLocal` class.
let callstacks_ptr = &raw mut CALLSTACKS;
unsafe {
if let Some(c) = (*&raw mut CALLSTACKS).as_mut() {
if let Some(c) = (*callstacks_ptr).as_mut() {
Some(&*c.get_or_default().get())
} else {
None
Expand All @@ -589,14 +592,11 @@ impl CallTraceCollector for FullBacktraceCollector {
ET: EmulatorModuleTuple<S>,
S: Unpin + UsesInput,
{
let callstacks_ptr = &raw mut CALLSTACKS;
// TODO handle Thumb
unsafe {
(*(*&raw mut CALLSTACKS)
.as_mut()
.unwrap()
.get_or_default()
.get())
.push(pc + call_len as GuestAddr);
(*(*callstacks_ptr).as_mut().unwrap().get_or_default().get())
.push(pc + call_len as GuestAddr);
}
}

Expand All @@ -611,12 +611,9 @@ impl CallTraceCollector for FullBacktraceCollector {
ET: EmulatorModuleTuple<S>,
S: Unpin + UsesInput,
{
let callstacks_ptr = &raw mut CALLSTACKS;
unsafe {
let v = &mut *(*&raw mut CALLSTACKS)
.as_mut()
.unwrap()
.get_or_default()
.get();
let v = &mut *(*callstacks_ptr).as_mut().unwrap().get_or_default().get();
if !v.is_empty() {
// if *v.last().unwrap() == ret_addr {
// v.pop();
Expand Down
3 changes: 2 additions & 1 deletion libafl_qemu/src/modules/edges/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ mod generators {
{
unsafe {
assert!(LIBAFL_QEMU_EDGES_MAP_MASK_MAX > 0);
assert_ne!(*&raw const LIBAFL_QEMU_EDGES_MAP_SIZE_PTR, ptr::null_mut());
let edges_map_size_ptr = &raw const LIBAFL_QEMU_EDGES_MAP_SIZE_PTR;
assert_ne!(*edges_map_size_ptr, ptr::null_mut());
}

#[cfg(feature = "usermode")]
Expand Down
3 changes: 2 additions & 1 deletion libafl_qemu/src/qemu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,8 @@ impl Qemu {
FatPtr,
>(callback));
libafl_qemu_add_gdb_cmd(Some(gdb_cmd), ptr::from_ref(&*fat) as *mut c_void);
(*&raw mut GDB_COMMANDS).push(fat);
let commands_ptr = &raw mut GDB_COMMANDS;
(*commands_ptr).push(fat);
}

pub fn gdb_reply(&self, output: &str) {
Expand Down

0 comments on commit 4743fbe

Please sign in to comment.