From fa839bb08dbf4a03b8fc65e01fb138d10e01e1e6 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Mon, 23 May 2022 13:42:51 +0200 Subject: [PATCH] More docs and less pub types (#646) * more docs * nits * fixes * win fix * fmt --- fuzzers/libfuzzer_libpng/src/lib.rs | 4 +-- libafl/src/executors/inprocess.rs | 40 ++++++++++++++++------------- libafl/src/mutators/gramatron.rs | 2 +- libafl/src/schedulers/powersched.rs | 7 ++++- libafl_frida/src/alloc.rs | 21 +++++++++++++-- 5 files changed, 49 insertions(+), 25 deletions(-) diff --git a/fuzzers/libfuzzer_libpng/src/lib.rs b/fuzzers/libfuzzer_libpng/src/lib.rs index 211b3999e9..e2b531de07 100644 --- a/fuzzers/libfuzzer_libpng/src/lib.rs +++ b/fuzzers/libfuzzer_libpng/src/lib.rs @@ -27,9 +27,7 @@ use libafl::{ mutators::scheduled::{havoc_mutations, tokens_mutations, StdScheduledMutator}, mutators::token_mutations::Tokens, observers::{HitcountsMapObserver, StdMapObserver, TimeObserver}, - schedulers::{ - powersched::PowerSchedule, IndexesLenTimeMinimizerScheduler, StdWeightedScheduler, - }, + schedulers::{IndexesLenTimeMinimizerScheduler, StdWeightedScheduler}, stages::{calibrate::CalibrationStage, power::StdPowerMutationalStage}, state::{HasCorpus, HasMetadata, StdState}, Error, diff --git a/libafl/src/executors/inprocess.rs b/libafl/src/executors/inprocess.rs index d6821eaeb0..f1f73a0375 100644 --- a/libafl/src/executors/inprocess.rs +++ b/libafl/src/executors/inprocess.rs @@ -384,15 +384,18 @@ impl InProcessHandlers { /// The global state of the in-process harness. #[derive(Debug)] -#[allow(missing_docs)] -pub struct InProcessExecutorHandlerData { - pub state_ptr: *mut c_void, - pub event_mgr_ptr: *mut c_void, - pub fuzzer_ptr: *mut c_void, - pub executor_ptr: *const c_void, +pub(crate) struct InProcessExecutorHandlerData { + state_ptr: *mut c_void, + event_mgr_ptr: *mut c_void, + fuzzer_ptr: *mut c_void, + executor_ptr: *const c_void, pub current_input_ptr: *const c_void, - pub crash_handler: *const c_void, - pub timeout_handler: *const c_void, + /// The timeout handler + #[allow(unused)] // for no_std + crash_handler: *const c_void, + /// The timeout handler + #[allow(unused)] // for no_std + timeout_handler: *const c_void, #[cfg(windows)] pub tp_timer: *mut c_void, #[cfg(windows)] @@ -446,7 +449,7 @@ impl InProcessExecutorHandlerData { } /// Exception handling needs some nasty unsafe. -pub static mut GLOBAL_STATE: InProcessExecutorHandlerData = InProcessExecutorHandlerData { +pub(crate) static mut GLOBAL_STATE: InProcessExecutorHandlerData = InProcessExecutorHandlerData { /// The state ptr for signal handling state_ptr: ptr::null_mut(), /// The event manager ptr for signal handling @@ -527,7 +530,7 @@ mod unix_signal_handler { state::{HasClientPerfMonitor, HasMetadata, HasSolutions}, }; - pub type HandlerFuncPtr = + pub(crate) type HandlerFuncPtr = unsafe fn(Signal, siginfo_t, &mut ucontext_t, data: &mut InProcessExecutorHandlerData); /// A handler that does nothing. @@ -649,7 +652,7 @@ mod unix_signal_handler { } #[cfg(unix)] - pub unsafe fn inproc_timeout_handler( + pub(crate) unsafe fn inproc_timeout_handler( _signal: Signal, _info: siginfo_t, _context: &mut ucontext_t, @@ -729,7 +732,7 @@ mod unix_signal_handler { /// Will be used for signal handling. /// It will store the current State to shmem, then exit. #[allow(clippy::too_many_lines)] - pub unsafe fn inproc_crash_handler( + pub(crate) unsafe fn inproc_crash_handler( signal: Signal, _info: siginfo_t, _context: &mut ucontext_t, @@ -880,7 +883,8 @@ mod windows_exception_handler { use core::sync::atomic::{compiler_fence, Ordering}; use windows::Win32::System::Threading::ExitProcess; - pub type HandlerFuncPtr = unsafe fn(*mut EXCEPTION_POINTERS, &mut InProcessExecutorHandlerData); + pub(crate) type HandlerFuncPtr = + unsafe fn(*mut EXCEPTION_POINTERS, &mut InProcessExecutorHandlerData); /*pub unsafe fn nop_handler( _code: ExceptionCode, @@ -1104,7 +1108,7 @@ mod windows_exception_handler { } #[allow(clippy::too_many_lines)] - pub unsafe fn inproc_crash_handler( + pub(crate) unsafe fn inproc_crash_handler( exception_pointers: *mut EXCEPTION_POINTERS, data: &mut InProcessExecutorHandlerData, ) where @@ -1244,7 +1248,7 @@ mod windows_exception_handler { /// The signature of the crash handler function #[cfg(all(feature = "std", unix))] -pub type ForkHandlerFuncPtr = +pub(crate) type ForkHandlerFuncPtr = unsafe fn(Signal, siginfo_t, &mut ucontext_t, data: &mut InProcessForkExecutorGlobalData); /// The inmem fork executor's handlers. @@ -1306,7 +1310,7 @@ impl InChildProcessHandlers { /// The global state of the in-process-fork harness. #[cfg(all(feature = "std", unix))] #[derive(Debug)] -pub struct InProcessForkExecutorGlobalData { +pub(crate) struct InProcessForkExecutorGlobalData { /// Stores a pointer to the fork executor struct pub executor_ptr: *const c_void, /// Stores a pointer to the state @@ -1349,7 +1353,7 @@ impl InProcessForkExecutorGlobalData { /// a static variable storing the global state #[cfg(all(feature = "std", unix))] -pub static mut FORK_EXECUTOR_GLOBAL_DATA: InProcessForkExecutorGlobalData = +pub(crate) static mut FORK_EXECUTOR_GLOBAL_DATA: InProcessForkExecutorGlobalData = InProcessForkExecutorGlobalData { executor_ptr: ptr::null(), crash_handler: ptr::null(), @@ -1591,7 +1595,7 @@ pub mod child_signal_handlers { /// The function should only be called from a child crash handler. /// It will dereference the `data` pointer and assume it's valid. #[cfg(unix)] - pub unsafe fn child_crash_handler( + pub(crate) unsafe fn child_crash_handler( _signal: Signal, _info: siginfo_t, _context: &mut ucontext_t, diff --git a/libafl/src/mutators/gramatron.rs b/libafl/src/mutators/gramatron.rs index ad49479aa3..4d8f98dd46 100644 --- a/libafl/src/mutators/gramatron.rs +++ b/libafl/src/mutators/gramatron.rs @@ -68,8 +68,8 @@ where /// The metadata used for `gramatron` #[derive(Debug, Serialize, Deserialize)] -#[allow(missing_docs)] pub struct GramatronIdxMapMetadata { + /// The map containing a vec for each terminal pub map: HashMap>, } diff --git a/libafl/src/schedulers/powersched.rs b/libafl/src/schedulers/powersched.rs index f9e6055df2..e1b110ba14 100644 --- a/libafl/src/schedulers/powersched.rs +++ b/libafl/src/schedulers/powersched.rs @@ -129,14 +129,19 @@ impl SchedulerMetadata { } /// The power schedule to use -#[allow(missing_docs)] #[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)] pub enum PowerSchedule { + /// The `explore" power schedule EXPLORE, + /// The `exploit` power schedule EXPLOIT, + /// The `fast` power schedule FAST, + /// The `coe` power schedule COE, + /// The `lin` power schedule LIN, + /// The `quad` power schedule QUAD, } diff --git a/libafl_frida/src/alloc.rs b/libafl_frida/src/alloc.rs index 9bc02d17b7..b907ca92d4 100644 --- a/libafl_frida/src/alloc.rs +++ b/libafl_frida/src/alloc.rs @@ -27,20 +27,31 @@ use crate::asan::errors::{AsanError, AsanErrors}; /// An allocator wrapper with binary-only address sanitization #[derive(Debug)] -#[allow(missing_docs)] pub struct Allocator { + /// The fuzzer options #[allow(dead_code)] options: FuzzerOptions, + /// The page size page_size: usize, + /// The shadow offsets shadow_offset: usize, + /// The shadow bit shadow_bit: usize, + /// If the shadow is pre-allocated pre_allocated_shadow: bool, + /// All tracked allocations allocations: HashMap, + /// The shadow memory pages shadow_pages: RangeSet, + /// A list of allocations allocation_queue: BTreeMap>, + /// The size of the largest allocation largest_allocation: usize, + /// The total size of all allocations combined total_allocation_size: usize, + /// The base address of the shadow memory base_mapping_addr: usize, + /// The current mapping address current_mapping_addr: usize, } @@ -57,14 +68,20 @@ macro_rules! map_to_shadow { /// Metadata for an allocation #[derive(Clone, Debug, Default, Serialize, Deserialize)] -#[allow(missing_docs)] pub struct AllocationMetadata { + /// The address of the allocation pub address: usize, + /// The size of the allocation pub size: usize, + /// The actual allocated size, including metadata pub actual_size: usize, + /// A backtrace to the allocation location pub allocation_site_backtrace: Option, + /// A backtrace to the location where this memory has been released pub release_site_backtrace: Option, + /// If the allocation has been freed pub freed: bool, + /// If the allocation was done with a size of 0 pub is_malloc_zero: bool, }