Skip to content

Commit 977ff10

Browse files
tokatokaYour Nametoka
authored
Make corpus and solution not mutually exclusive (#3029)
* make fuzzer great again * crash handlers * hello from windows * fk * gee * m * temporary fix * f * mm * CICI * fixer * Fix Dockerfile * lol * clp * Fuck you clippy * This lint makes no sense, 0 * ?? * a * fix * this lint makes 0 sense * mm * clp * a * a * clp * clippy * clp * mm * FMT * p --------- Co-authored-by: Your Name <[email protected]> Co-authored-by: toka <[email protected]>
1 parent 89342b2 commit 977ff10

File tree

48 files changed

+399
-522
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+399
-522
lines changed

Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ std_instead_of_core = "deny"
156156
cargo = { level = "warn", priority = -1 }
157157

158158
# Allow
159-
negative_feature_names = "allow" # TODO: turn into 'warn' when working
160-
multiple_crate_versions = "allow" # TODO: turn into `warn` when working
159+
negative_feature_names = "allow" # TODO: turn into 'warn' when working
160+
multiple_crate_versions = "allow" # TODO: turn into `warn` when working
161161
unreadable_literal = "allow"
162162
type_repetition_in_bounds = "allow"
163163
missing_errors_doc = "allow"
@@ -169,8 +169,8 @@ module_name_repetitions = "allow"
169169
unsafe_derive_deserialize = "allow"
170170
similar_names = "allow"
171171
too_many_lines = "allow"
172-
comparison_chain = "allow" # This lint makes **ZERO** sense
173-
172+
comparison_chain = "allow" # This lint makes **ZERO** sense
173+
unnecessary_debug_formatting = "allow" # :thumbsdown: :thumbsdown: :thumbsdown: :thumbsdown: :thumbsdown: :thumbsdown:
174174

175175
[workspace.lints.rustdoc]
176176
# Deny

Dockerfile

+22-17
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,33 @@ RUN set -ex &&\
6868
chmod +x llvm.sh &&\
6969
./llvm.sh ${LLVM_VERSION}
7070

71+
RUN apt-get update && \
72+
apt-get install -y \
73+
clang-format-${LLVM_VERSION}
74+
7175
RUN git config --global core.pager cat
7276

7377
# Install a modern version of QEMU
74-
7578
WORKDIR /root
7679
ENV QEMU_VER=9.2.1
77-
RUN wget https://download.qemu.org/qemu-${QEMU_VER}.tar.xz
78-
RUN tar xvJf qemu-${QEMU_VER}.tar.xz
79-
WORKDIR /root/qemu-${QEMU_VER}
80-
RUN ./configure --target-list="\
81-
arm-linux-user,\
82-
aarch64-linux-user,\
83-
i386-linux-user,\
84-
ppc-linux-user,\
85-
mips-linux-user,\
86-
arm-softmmu,\
87-
aarch64-softmmu,\
88-
i386-softmmu,\
89-
ppc-softmmu,\
90-
mips-softmmu"
91-
RUN make -j
92-
RUN make install
80+
RUN wget https://download.qemu.org/qemu-${QEMU_VER}.tar.xz && \
81+
tar xvJf qemu-${QEMU_VER}.tar.xz && \
82+
cd /root/qemu-${QEMU_VER} && \
83+
./configure --target-list="\
84+
arm-linux-user,\
85+
aarch64-linux-user,\
86+
i386-linux-user,\
87+
ppc-linux-user,\
88+
mips-linux-user,\
89+
arm-softmmu,\
90+
aarch64-softmmu,\
91+
i386-softmmu,\
92+
ppc-softmmu,\
93+
mips-softmmu" && \
94+
make -j && \
95+
make install && \
96+
cd /root && \
97+
rm -rf qemu-${QEMU_VER}
9398

9499
# Copy a dummy.rs and Cargo.toml first, so that dependencies are cached
95100
WORKDIR /libafl

fuzzers/forkserver/libafl-fuzz/src/corpus.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,10 @@ pub fn check_autoresume(fuzzer_dir: &Path, auto_resume: bool) -> Result<Flock<Fi
146146

147147
pub fn create_dir_if_not_exists(path: &Path) -> io::Result<()> {
148148
if path.is_file() {
149-
return Err(io::Error::new(
150-
// TODO: change this to ErrorKind::NotADirectory
151-
// when stabilitzed https://github.com/rust-lang/rust/issues/86442
152-
io::ErrorKind::Other,
153-
format!("{} expected a directory; got a file", path.display()),
154-
));
149+
return Err(io::Error::other(format!(
150+
"{} expected a directory; got a file",
151+
path.display()
152+
)));
155153
}
156154
match std::fs::create_dir(path) {
157155
Ok(()) => Ok(()),

fuzzers/forkserver/libafl-fuzz/src/feedback/seed.rs

-6
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,6 @@ where
100100
Ok(())
101101
}
102102

103-
/// Discard the stored metadata in case that the testcase is not added to the corpus
104-
#[inline]
105-
fn discard_metadata(&mut self, state: &mut S, input: &I) -> Result<(), Error> {
106-
self.inner.discard_metadata(state, input)?;
107-
Ok(())
108-
}
109103
#[cfg(feature = "track_hit_feedbacks")]
110104
fn last_result(&self) -> Result<bool, Error> {
111105
self.inner.last_result()

fuzzers/inprocess/fuzzbench_ctx/src/lib.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,6 @@ fn fuzz(
345345

346346
let mut tracing_harness = harness;
347347
let ctx_hook = CtxHook::new();
348-
// Create the executor for an in-process function with one observer for edge coverage and one for the execution time
349-
let mut executor = HookableInProcessExecutor::with_timeout_generic(
350-
tuple_list!(ctx_hook),
351-
&mut harness,
352-
tuple_list!(edges_observer, time_observer),
353-
&mut fuzzer,
354-
&mut state,
355-
&mut mgr,
356-
timeout,
357-
)?;
358348

359349
// Setup a tracing stage in which we log comparisons
360350
let tracing = TracingStage::new(
@@ -369,6 +359,17 @@ fn fuzz(
369359
// Give it more time!
370360
);
371361

362+
// Create the executor for an in-process function with one observer for edge coverage and one for the execution time
363+
let mut executor = HookableInProcessExecutor::with_timeout_generic(
364+
tuple_list!(ctx_hook),
365+
&mut harness,
366+
tuple_list!(edges_observer, time_observer),
367+
&mut fuzzer,
368+
&mut state,
369+
&mut mgr,
370+
timeout,
371+
)?;
372+
372373
// The order of the stages matter!
373374
let mut stages = tuple_list!(calibration, tracing, i2s, power);
374375

libafl/src/events/launcher.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ where
274274
// Spawn clients
275275
let mut index = 0_usize;
276276
for bind_to in core_ids {
277-
if self.cores.ids.iter().any(|&x| x == bind_to) {
277+
if self.cores.ids.contains(&bind_to) {
278278
for overcommit_id in 0..self.overcommit {
279279
index += 1;
280280
self.shmem_provider.pre_fork()?;
@@ -456,7 +456,7 @@ where
456456
//spawn clients
457457
let mut index = 0;
458458
for core_id in core_ids {
459-
if self.cores.ids.iter().any(|&x| x == core_id) {
459+
if self.cores.ids.contains(&core_id) {
460460
for overcommit_i in 0..self.overcommit {
461461
index += 1;
462462
// Forward own stdio to child processes, if requested by user
@@ -748,7 +748,7 @@ where
748748
// Spawn clients
749749
let mut index = 0_usize;
750750
for bind_to in core_ids {
751-
if self.cores.ids.iter().any(|&x| x == bind_to) {
751+
if self.cores.ids.contains(&bind_to) {
752752
for overcommit_id in 0..self.overcommit {
753753
index += 1;
754754
self.shmem_provider.pre_fork()?;

libafl/src/executors/hooks/inprocess.rs

+21-14
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use windows::Win32::System::Threading::{CRITICAL_SECTION, PTP_TIMER};
2424
#[cfg(feature = "std")]
2525
use crate::executors::hooks::timer::TimerStruct;
2626
use crate::{
27-
Error, HasObjective,
27+
Error, HasFeedback, HasObjective,
2828
events::{EventFirer, EventRestarter},
2929
executors::{Executor, HasObservers, hooks::ExecutorHook, inprocess::HasInProcessHooks},
3030
feedbacks::Feedback,
@@ -202,7 +202,7 @@ impl<I, S> ExecutorHook<I, S> for InProcessHooks<I, S> {
202202
// Imagine there are two executors, you have to set the correct crash handlers for each of the executor.
203203
unsafe {
204204
let data = &raw mut GLOBAL_STATE;
205-
assert!((*data).crash_handler == null());
205+
assert!((*data).crash_handler.is_null());
206206
// usually timeout handler and crash handler is set together
207207
// so no check for timeout handler is null or not
208208
(*data).crash_handler = self.crash_handler;
@@ -232,14 +232,15 @@ impl<I, S> InProcessHooks<I, S> {
232232
/// Create new [`InProcessHooks`].
233233
#[cfg(unix)]
234234
#[allow(unused_variables)] // for `exec_tmout` without `std`
235-
pub fn new<E, EM, OF, Z>(exec_tmout: Duration) -> Result<Self, Error>
235+
pub fn new<E, EM, F, OF, Z>(exec_tmout: Duration) -> Result<Self, Error>
236236
where
237237
E: Executor<EM, I, S, Z> + HasObservers + HasInProcessHooks<I, S>,
238238
E::Observers: ObserversTuple<I, S>,
239239
EM: EventFirer<I, S> + EventRestarter<S>,
240+
F: Feedback<EM, I, E::Observers, S>,
240241
OF: Feedback<EM, I, E::Observers, S>,
241242
S: HasExecutions + HasSolutions<I> + HasCurrentTestcase<I>,
242-
Z: HasObjective<Objective = OF>,
243+
Z: HasObjective<Objective = OF> + HasFeedback<Feedback = F>,
243244
I: Input + Clone,
244245
{
245246
// # Safety
@@ -249,7 +250,7 @@ impl<I, S> InProcessHooks<I, S> {
249250
#[cfg(all(not(miri), unix, feature = "std"))]
250251
let data = unsafe { &raw mut GLOBAL_STATE };
251252
#[cfg(feature = "std")]
252-
unix_signal_handler::setup_panic_hook::<E, EM, I, OF, S, Z>();
253+
unix_signal_handler::setup_panic_hook::<E, EM, F, I, OF, S, Z>();
253254
// # Safety
254255
// Setting up the signal handlers with a pointer to the `GLOBAL_STATE` which should not be NULL at this point.
255256
// We are the sole users of `GLOBAL_STATE` right now, and only dereference it in case of Segfault/Panic.
@@ -262,10 +263,10 @@ impl<I, S> InProcessHooks<I, S> {
262263
compiler_fence(Ordering::SeqCst);
263264
Ok(Self {
264265
#[cfg(feature = "std")]
265-
crash_handler: unix_signal_handler::inproc_crash_handler::<E, EM, I, OF, S, Z>
266+
crash_handler: unix_signal_handler::inproc_crash_handler::<E, EM, F, I, OF, S, Z>
266267
as *const c_void,
267268
#[cfg(feature = "std")]
268-
timeout_handler: unix_signal_handler::inproc_timeout_handler::<E, EM, I, OF, S, Z>
269+
timeout_handler: unix_signal_handler::inproc_timeout_handler::<E, EM, F, I, OF, S, Z>
269270
as *const _,
270271
#[cfg(feature = "std")]
271272
timer: TimerStruct::new(exec_tmout),
@@ -276,15 +277,16 @@ impl<I, S> InProcessHooks<I, S> {
276277
/// Create new [`InProcessHooks`].
277278
#[cfg(windows)]
278279
#[allow(unused_variables)] // for `exec_tmout` without `std`
279-
pub fn new<E, EM, OF, Z>(exec_tmout: Duration) -> Result<Self, Error>
280+
pub fn new<E, EM, F, OF, Z>(exec_tmout: Duration) -> Result<Self, Error>
280281
where
281282
E: Executor<EM, I, S, Z> + HasObservers + HasInProcessHooks<I, S>,
282283
E::Observers: ObserversTuple<I, S>,
283284
EM: EventFirer<I, S> + EventRestarter<S>,
284285
I: Input + Clone,
286+
F: Feedback<EM, I, E::Observers, S>,
285287
OF: Feedback<EM, I, E::Observers, S>,
286288
S: HasExecutions + HasSolutions<I> + HasCurrentTestcase<I>,
287-
Z: HasObjective<Objective = OF>,
289+
Z: HasObjective<Objective = OF> + HasFeedback<Feedback = F>,
288290
{
289291
let ret;
290292
#[cfg(feature = "std")]
@@ -293,6 +295,7 @@ impl<I, S> InProcessHooks<I, S> {
293295
crate::executors::hooks::windows::windows_exception_handler::setup_panic_hook::<
294296
E,
295297
EM,
298+
F,
296299
I,
297300
OF,
298301
S,
@@ -304,6 +307,7 @@ impl<I, S> InProcessHooks<I, S> {
304307
crate::executors::hooks::windows::windows_exception_handler::inproc_crash_handler::<
305308
E,
306309
EM,
310+
F,
307311
I,
308312
OF,
309313
S,
@@ -313,6 +317,7 @@ impl<I, S> InProcessHooks<I, S> {
313317
crate::executors::hooks::windows::windows_exception_handler::inproc_timeout_handler::<
314318
E,
315319
EM,
320+
F,
316321
I,
317322
OF,
318323
S,
@@ -339,13 +344,14 @@ impl<I, S> InProcessHooks<I, S> {
339344
/// Create a new [`InProcessHooks`]
340345
#[cfg(all(not(unix), not(windows)))]
341346
#[expect(unused_variables)]
342-
pub fn new<E, EM, OF, Z>(exec_tmout: Duration) -> Result<Self, Error>
347+
pub fn new<E, EM, F, OF, Z>(exec_tmout: Duration) -> Result<Self, Error>
343348
where
344349
E: Executor<EM, I, S, Z> + HasObservers + HasInProcessHooks<I, S>,
345350
EM: EventFirer<I, S> + EventRestarter<S>,
351+
F: Feedback<EM, I, E::Observers, S>,
346352
OF: Feedback<EM, I, E::Observers, S>,
347353
S: HasExecutions + HasSolutions<I>,
348-
Z: HasObjective<Objective = OF>,
354+
Z: HasObjective<Objective = OF> + HasFeedback<Feedback = F>,
349355
{
350356
#[cfg_attr(miri, allow(unused_variables))]
351357
let ret = Self {
@@ -472,17 +478,18 @@ impl InProcessExecutorHandlerData {
472478
///
473479
/// Should only be called to signal a crash in the target
474480
#[cfg(all(unix, feature = "std"))]
475-
pub unsafe fn maybe_report_crash<E, EM, I, OF, S, Z>(
481+
pub unsafe fn maybe_report_crash<E, EM, F, I, OF, S, Z>(
476482
&mut self,
477483
bsod_info: Option<BsodInfo>,
478484
) -> bool
479485
where
480486
E: Executor<EM, I, S, Z> + HasObservers,
481487
E::Observers: ObserversTuple<I, S>,
482488
EM: EventFirer<I, S> + EventRestarter<S>,
489+
F: Feedback<EM, I, E::Observers, S>,
483490
OF: Feedback<EM, I, E::Observers, S>,
484491
S: HasExecutions + HasSolutions<I> + HasCorpus<I> + HasCurrentTestcase<I>,
485-
Z: HasObjective<Objective = OF>,
492+
Z: HasObjective<Objective = OF> + HasFeedback<Feedback = F>,
486493
I: Input + Clone,
487494
{
488495
unsafe {
@@ -510,7 +517,7 @@ impl InProcessExecutorHandlerData {
510517
}
511518
}
512519

513-
run_observers_and_save_state::<E, EM, I, OF, S, Z>(
520+
run_observers_and_save_state::<E, EM, F, I, OF, S, Z>(
514521
executor,
515522
state,
516523
input,

libafl/src/executors/hooks/timer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl TimerStruct {
178178
pub unsafe fn new(exec_tmout: Duration, timeout_handler: *const c_void) -> Self {
179179
let milli_sec = exec_tmout.as_millis() as i64;
180180

181-
let timeout_handler: PTP_TIMER_CALLBACK = unsafe { std::mem::transmute(timeout_handler) };
181+
let timeout_handler: PTP_TIMER_CALLBACK = unsafe { core::mem::transmute(timeout_handler) };
182182
let ptp_timer = unsafe {
183183
CreateThreadpoolTimer(
184184
Some(timeout_handler),

0 commit comments

Comments
 (0)