From 8a8c82a72bc9ff48d791c6b2611b083139734550 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Sun, 4 Dec 2022 19:24:10 +0100 Subject: [PATCH 01/10] Fix clippy --- libafl/examples/llmp_test/main.rs | 5 +-- libafl/src/bolts/core_affinity.rs | 6 ++-- libafl/src/bolts/llmp.rs | 36 ++++++++-------------- libafl/src/bolts/os/unix_signals.rs | 3 +- libafl/src/bolts/shmem.rs | 18 ++++------- libafl/src/events/llmp.rs | 5 +-- libafl/src/events/mod.rs | 8 +++-- libafl/src/events/simple.rs | 3 +- libafl/src/executors/forkserver.rs | 3 +- libafl/src/executors/inprocess.rs | 3 +- libafl/src/feedbacks/differential.rs | 3 +- libafl/src/monitors/mod.rs | 3 +- libafl/src/mutators/token_mutations.rs | 6 ++-- libafl/src/observers/mod.rs | 4 +-- libafl/src/observers/value.rs | 9 +++--- libafl/src/schedulers/accounting.rs | 3 +- libafl/src/schedulers/minimizer.rs | 9 ++---- libafl/src/stages/generalization.rs | 3 +- libafl_cc/build.rs | 3 +- libafl_concolic/symcc_runtime/build.rs | 3 +- libafl_frida/src/alloc.rs | 3 +- libafl_frida/src/asan/asan_rt.rs | 28 ++++++++--------- libafl_frida/src/asan/errors.rs | 10 ++---- libafl_qemu/libafl_qemu_build/src/build.rs | 5 +-- libafl_targets/build.rs | 13 ++++---- 25 files changed, 72 insertions(+), 123 deletions(-) diff --git a/libafl/examples/llmp_test/main.rs b/libafl/examples/llmp_test/main.rs index 48f29e6650..dbdf8d7d93 100644 --- a/libafl/examples/llmp_test/main.rs +++ b/libafl/examples/llmp_test/main.rs @@ -48,10 +48,7 @@ fn adder_loop(port: u16) -> ! { } if current_result != last_result { - println!( - "Adder handled {} messages, reporting {} to broker", - msg_counter, current_result - ); + println!("Adder handled {msg_counter} messages, reporting {current_result} to broker"); client .send_buf(_TAG_MATH_RESULT_V1, ¤t_result.to_le_bytes()) diff --git a/libafl/src/bolts/core_affinity.rs b/libafl/src/bolts/core_affinity.rs index 5c9d865f06..9c32c41438 100644 --- a/libafl/src/bolts/core_affinity.rs +++ b/libafl/src/bolts/core_affinity.rs @@ -132,8 +132,7 @@ impl Cores { if cores.is_empty() { return Err(Error::illegal_argument(format!( - "No cores specified! parsed: {}", - args + "No cores specified! parsed: {args}" ))); } @@ -615,8 +614,7 @@ mod apple { Ok(()) } else { Err(Error::unknown(format!( - "Failed to set_for_current {:?}", - result + "Failed to set_for_current {result:?}" ))) } } diff --git a/libafl/src/bolts/llmp.rs b/libafl/src/bolts/llmp.rs index f2e587a06f..3d81657c54 100644 --- a/libafl/src/bolts/llmp.rs +++ b/libafl/src/bolts/llmp.rs @@ -466,9 +466,7 @@ unsafe fn _llmp_page_init(shmem: &mut SHM, sender_id: ClientId, allo if !allow_reinit { assert!( (*page).magic != PAGE_INITIALIZED_MAGIC, - "Tried to initialize page {:?} twice (for shmem {:?})", - page, - shmem + "Tried to initialize page {page:?} twice (for shmem {shmem:?})" ); } @@ -641,10 +639,7 @@ where } Err(Error::File(e, _)) if e.kind() == ErrorKind::AddrInUse => { // We are the client :) - println!( - "We're the client (internal port already bound by broker, {:#?})", - e - ); + println!("We're the client (internal port already bound by broker, {e:#?})"); Ok(LlmpConnection::IsClient { client: LlmpClient::create_attach_to_tcp(shmem_provider, port)?, }) @@ -1082,8 +1077,7 @@ where let page = self.out_shmems.last_mut().unwrap().page_mut(); if msg.is_null() || !llmp_msg_in_page(page, msg) { return Err(Error::unknown(format!( - "Llmp Message {:?} is null or not in current page", - msg + "Llmp Message {msg:?} is null or not in current page" ))); } @@ -1189,8 +1183,7 @@ where match unsafe { self.alloc_next_if_space(buf_len) } { Some(msg) => Ok(msg), None => Err(Error::unknown(format!( - "Error allocating {} bytes in shmap", - buf_len + "Error allocating {buf_len} bytes in shmap" ))), } } @@ -1258,8 +1251,7 @@ where || tag == LLMP_TAG_UNSET { return Err(Error::unknown(format!( - "Reserved tag supplied to send_buf ({:#X})", - tag + "Reserved tag supplied to send_buf ({tag:#X})" ))); } @@ -1282,8 +1274,7 @@ where || tag == LLMP_TAG_UNSET { return Err(Error::unknown(format!( - "Reserved tag supplied to send_buf ({:#X})", - tag + "Reserved tag supplied to send_buf ({tag:#X})" ))); } @@ -1742,8 +1733,7 @@ where let page_size = self.shmem.as_slice().len() - size_of::(); if offset > page_size { Err(Error::illegal_argument(format!( - "Msg offset out of bounds (size: {}, requested offset: {})", - page_size, offset + "Msg offset out of bounds (size: {page_size}, requested offset: {offset})" ))) } else { unsafe { Ok(((*page).messages.as_mut_ptr() as *mut u8).add(offset) as *mut LlmpMsg) } @@ -2048,7 +2038,7 @@ where /// This function returns the [`ShMemDescription`] the client uses to place incoming messages. /// The thread exits, when the remote broker disconnects. #[cfg(feature = "std")] - #[allow(clippy::let_and_return)] + #[allow(clippy::let_and_return, clippy::too_many_lines)] fn b2b_thread_on( mut stream: TcpStream, b2b_client_id: ClientId, @@ -2106,8 +2096,7 @@ where Ok(Some((client_id, tag, flags, payload))) => { if client_id == b2b_client_id { println!( - "Ignored message we probably sent earlier (same id), TAG: {:x}", - tag + "Ignored message we probably sent earlier (same id), TAG: {tag:x}" ); continue; } @@ -2127,7 +2116,7 @@ where payload: payload.to_vec(), }, ) { - println!("Got error {} while trying to forward a message to broker {}, exiting thread", e, peer_address); + println!("Got error {e} while trying to forward a message to broker {peer_address}, exiting thread"); return; } } @@ -2135,7 +2124,7 @@ where println!("Local broker is shutting down, exiting thread"); return; } - Err(e) => panic!("Error reading from local page! {}", e), + Err(e) => panic!("Error reading from local page! {e}"), } } @@ -2171,8 +2160,7 @@ where if let Error::File(e, _) = e { if e.kind() == ErrorKind::UnexpectedEof { println!( - "Broker {} seems to have disconnected, exiting", - peer_address + "Broker {peer_address} seems to have disconnected, exiting" ); return; } diff --git a/libafl/src/bolts/os/unix_signals.rs b/libafl/src/bolts/os/unix_signals.rs index 438fc855b8..9c7cca417d 100644 --- a/libafl/src/bolts/os/unix_signals.rs +++ b/libafl/src/bolts/os/unix_signals.rs @@ -391,8 +391,7 @@ pub unsafe fn setup_signal_handler(handler: &mut T) -> Res // Rust always panics on OOM, so we will, too. assert!( !SIGNAL_STACK_PTR.is_null(), - "Failed to allocate signal stack with {} bytes!", - SIGNAL_STACK_SIZE + "Failed to allocate signal stack with {SIGNAL_STACK_SIZE} bytes!" ); } let mut ss: stack_t = mem::zeroed(); diff --git a/libafl/src/bolts/shmem.rs b/libafl/src/bolts/shmem.rs index cd9b01b03a..819c9104eb 100644 --- a/libafl/src/bolts/shmem.rs +++ b/libafl/src/bolts/shmem.rs @@ -468,8 +468,7 @@ where Ok(()) } else { Err(Error::unknown(format!( - "Wrong result read from pipe! Expected 0, got {:?}", - ret + "Wrong result read from pipe! Expected 0, got {ret:?}" ))) } } @@ -630,8 +629,7 @@ pub mod unix_shmem { if shm_fd == -1 { perror(b"shm_open\0".as_ptr() as *const _); return Err(Error::unknown(format!( - "Failed to shm_open map with id {:?}", - shmem_ctr + "Failed to shm_open map with id {shmem_ctr:?}" ))); } @@ -640,8 +638,7 @@ pub mod unix_shmem { perror(b"ftruncate\0".as_ptr() as *const _); shm_unlink(filename_path.as_ptr() as *const _); return Err(Error::unknown(format!( - "setup_shm(): ftruncate() failed for map with id {:?}", - shmem_ctr + "setup_shm(): ftruncate() failed for map with id {shmem_ctr:?}" ))); } @@ -659,8 +656,7 @@ pub mod unix_shmem { close(shm_fd); shm_unlink(filename_path.as_ptr() as *const _); return Err(Error::unknown(format!( - "mmap() failed for map with id {:?}", - shmem_ctr + "mmap() failed for map with id {shmem_ctr:?}" ))); } @@ -691,8 +687,7 @@ pub mod unix_shmem { perror(b"mmap\0".as_ptr() as *const _); close(shm_fd); return Err(Error::unknown(format!( - "mmap() failed for map with fd {:?}", - shm_fd + "mmap() failed for map with fd {shm_fd:?}" ))); } @@ -997,8 +992,7 @@ pub mod unix_shmem { let fd = open(device_path.as_ptr(), O_RDWR); if fd == -1 { return Err(Error::unknown(format!( - "Failed to open the ashmem device at {:?}", - device_path + "Failed to open the ashmem device at {device_path:?}" ))); } diff --git a/libafl/src/events/llmp.rs b/libafl/src/events/llmp.rs index 0e0d4c7477..365031aa17 100644 --- a/libafl/src/events/llmp.rs +++ b/libafl/src/events/llmp.rs @@ -398,10 +398,7 @@ where executions: _, } => { #[cfg(feature = "std")] - println!( - "Received new Testcase from {} ({:?})", - _client_id, client_config - ); + println!("Received new Testcase from {_client_id} ({client_config:?})"); let _res = if client_config.match_with(&self.configuration) && observers_buf.is_some() diff --git a/libafl/src/events/mod.rs b/libafl/src/events/mod.rs index b8d34ed54c..30a6d615c4 100644 --- a/libafl/src/events/mod.rs +++ b/libafl/src/events/mod.rs @@ -41,8 +41,8 @@ pub static mut SHUTDOWN_SIGHANDLER_DATA: ShutdownSignalData = ShutdownSignalData shutdown_handler: core::ptr::null(), }; -/// A signal handler for releasing staterestore shmem -/// This struct holds a pointer to StateRestore and clean up the shmem segment used by it. +/// A signal handler for releasing `StateRestore` `ShMem` +/// This struct holds a pointer to `StateRestore` and clean up the `ShMem` segment used by it. #[cfg(all(unix, feature = "std"))] #[derive(Debug, Clone)] pub struct ShutdownSignalData { @@ -58,6 +58,10 @@ pub type ShutdownFuncPtr = /// Shutdown handler. `SigTerm`, `SigInterrupt`, `SigQuit` call this /// We can't handle SIGKILL in the signal handler, this means that you shouldn't kill your fuzzer with `kill -9` because then the shmem segments are never freed +/// +/// # Safety +/// +/// This will acceess `data` and write to the global `data.staterestorer_ptr` if it's not null. #[cfg(all(unix, feature = "std"))] pub unsafe fn shutdown_handler( signal: Signal, diff --git a/libafl/src/events/simple.rs b/libafl/src/events/simple.rs index 6e9ce50338..9498d95edf 100644 --- a/libafl/src/events/simple.rs +++ b/libafl/src/events/simple.rs @@ -292,8 +292,7 @@ where Ok(()) } else { Err(Error::unknown(format!( - "Received illegal message that message should not have arrived: {:?}.", - event + "Received illegal message that message should not have arrived: {event:?}." ))) } } diff --git a/libafl/src/executors/forkserver.rs b/libafl/src/executors/forkserver.rs index a00001e5b8..e58739c59d 100644 --- a/libafl/src/executors/forkserver.rs +++ b/libafl/src/executors/forkserver.rs @@ -249,8 +249,7 @@ impl Forkserver { Ok(_) => (), Err(err) => { return Err(Error::illegal_state(format!( - "Could not spawn the forkserver: {:#?}", - err + "Could not spawn the forkserver: {err:#?}" ))) } }; diff --git a/libafl/src/executors/inprocess.rs b/libafl/src/executors/inprocess.rs index 31f1af5d26..ca5f4168ea 100644 --- a/libafl/src/executors/inprocess.rs +++ b/libafl/src/executors/inprocess.rs @@ -845,8 +845,7 @@ mod unix_signal_handler { let si_addr = { _info.si_addr() as usize }; eprintln!( - "We crashed at addr 0x{:x}, but are not in the target... Bug in the fuzzer? Exiting.", - si_addr + "We crashed at addr 0x{si_addr:x}, but are not in the target... Bug in the fuzzer? Exiting." ); #[cfg(all(feature = "std", unix))] diff --git a/libafl/src/feedbacks/differential.rs b/libafl/src/feedbacks/differential.rs index 36b2d0dd94..b8268a53a1 100644 --- a/libafl/src/feedbacks/differential.rs +++ b/libafl/src/feedbacks/differential.rs @@ -75,8 +75,7 @@ where let o2_name = o2.name().to_string(); if o1_name == o2_name { Err(Error::illegal_argument(format!( - "DiffFeedback: observer names must be different (both were {})", - o1_name + "DiffFeedback: observer names must be different (both were {o1_name})" ))) } else { Ok(Self { diff --git a/libafl/src/monitors/mod.rs b/libafl/src/monitors/mod.rs index 882204bbd7..5e9b25d339 100644 --- a/libafl/src/monitors/mod.rs +++ b/libafl/src/monitors/mod.rs @@ -832,8 +832,7 @@ impl core::fmt::Display for ClientPerfMonitor { // Create the formatted string writeln!( f, - " {:6.4}: Scheduler\n {:6.4}: Manager", - scheduler_percent, manager_percent + " {scheduler_percent:6.4}: Scheduler\n {manager_percent:6.4}: Manager" )?; // Calculate each stage diff --git a/libafl/src/mutators/token_mutations.rs b/libafl/src/mutators/token_mutations.rs index f93d2a7bb5..7b17ecb032 100644 --- a/libafl/src/mutators/token_mutations.rs +++ b/libafl/src/mutators/token_mutations.rs @@ -113,8 +113,7 @@ impl Tokens { } if token_stop < token_start { return Err(Error::illegal_argument(format!( - "Tried to create tokens from illegal section: stop < start ({:?} < {:?})", - token_stop, token_start + "Tried to create tokens from illegal section: stop < start ({token_stop:?} < {token_start:?})" ))); } let section_size: usize = token_stop.offset_from(token_start).try_into().unwrap(); @@ -185,8 +184,7 @@ impl Tokens { Ok(val) => val, Err(_) => { return Err(Error::illegal_argument(format!( - "Illegal line (hex decoding): {}", - line + "Illegal line (hex decoding): {line}" ))) } }; diff --git a/libafl/src/observers/mod.rs b/libafl/src/observers/mod.rs index 28d099b57a..d94d0d1ddb 100644 --- a/libafl/src/observers/mod.rs +++ b/libafl/src/observers/mod.rs @@ -19,14 +19,11 @@ pub use stacktrace::*; pub mod concolic; pub mod value; -pub use value::*; - // Rust is breaking this with 'error: intrinsic safety mismatch between list of intrinsics within the compiler and core library intrinsics for intrinsic `type_id`' and so we disable this component for the moment //#[cfg(unstable_feature)] //pub mod owned; //#[cfg(unstable_feature)] //pub use owned::*; - use alloc::{ string::{String, ToString}, vec::Vec, @@ -34,6 +31,7 @@ use alloc::{ use core::{fmt::Debug, time::Duration}; use serde::{Deserialize, Serialize}; +pub use value::*; use crate::{ bolts::{ diff --git a/libafl/src/observers/value.rs b/libafl/src/observers/value.rs index fc6cf5aeca..41c87b66ea 100644 --- a/libafl/src/observers/value.rs +++ b/libafl/src/observers/value.rs @@ -1,19 +1,20 @@ //! A simple observer with a single value. -use alloc::boxed::Box; -use alloc::string::{String, ToString}; +use alloc::{ + boxed::Box, + string::{String, ToString}, +}; use core::fmt::Debug; use serde::{Deserialize, Serialize}; +use super::Observer; use crate::{ bolts::{ownedref::OwnedRef, tuples::Named}, inputs::UsesInput, Error, }; -use super::Observer; - /// A simple observer with a single value. /// /// The intent is that the value is something with interior mutability (e.g., a diff --git a/libafl/src/schedulers/accounting.rs b/libafl/src/schedulers/accounting.rs index fbd8cb8462..04b4fbde9a 100644 --- a/libafl/src/schedulers/accounting.rs +++ b/libafl/src/schedulers/accounting.rs @@ -210,8 +210,7 @@ where let must_remove = { let old_meta = old.metadata_mut().get_mut::().ok_or_else(|| { Error::key_not_found(format!( - "AccountingIndexesMetadata, needed by CoverageAccountingScheduler, not found in testcase #{}", - old_idx + "AccountingIndexesMetadata, needed by CoverageAccountingScheduler, not found in testcase #{old_idx}" )) })?; *old_meta.refcnt_mut() -= 1; diff --git a/libafl/src/schedulers/minimizer.rs b/libafl/src/schedulers/minimizer.rs index 13835e9f06..76d381dc56 100644 --- a/libafl/src/schedulers/minimizer.rs +++ b/libafl/src/schedulers/minimizer.rs @@ -209,8 +209,7 @@ where let factor = F::compute(&mut *entry, state)?; let meta = entry.metadata_mut().get_mut::().ok_or_else(|| { Error::key_not_found(format!( - "Metadata needed for MinimizerScheduler not found in testcase #{}", - idx + "Metadata needed for MinimizerScheduler not found in testcase #{idx}" )) })?; for elem in meta.as_slice() { @@ -229,8 +228,7 @@ where let must_remove = { let old_meta = old.metadata_mut().get_mut::().ok_or_else(|| { Error::key_not_found(format!( - "Metadata needed for MinimizerScheduler not found in testcase #{}", - old_idx + "Metadata needed for MinimizerScheduler not found in testcase #{old_idx}" )) })?; *old_meta.refcnt_mut() -= 1; @@ -283,8 +281,7 @@ where let mut entry = state.corpus().get(*idx)?.borrow_mut(); let meta = entry.metadata().get::().ok_or_else(|| { Error::key_not_found(format!( - "Metadata needed for MinimizerScheduler not found in testcase #{}", - idx + "Metadata needed for MinimizerScheduler not found in testcase #{idx}" )) })?; for elem in meta.as_slice() { diff --git a/libafl/src/stages/generalization.rs b/libafl/src/stages/generalization.rs index 4dd779d69a..d8e389227c 100644 --- a/libafl/src/stages/generalization.rs +++ b/libafl/src/stages/generalization.rs @@ -127,8 +127,7 @@ where let original = input.clone(); let meta = entry.metadata().get::().ok_or_else(|| { Error::key_not_found(format!( - "MapNoveltiesMetadata needed for GeneralizationStage not found in testcase #{} (check the arguments of MapFeedback::new(...))", - corpus_idx + "MapNoveltiesMetadata needed for GeneralizationStage not found in testcase #{corpus_idx} (check the arguments of MapFeedback::new(...))" )) })?; (payload, original, meta.as_slice().to_vec()) diff --git a/libafl_cc/build.rs b/libafl_cc/build.rs index 342c7d54ba..a9dc5cae31 100644 --- a/libafl_cc/build.rs +++ b/libafl_cc/build.rs @@ -46,8 +46,7 @@ fn find_llvm_config_brew() -> Result { match glob_results.last() { Some(path) => Ok(path.unwrap()), None => Err(format!( - "No llvm-config found in brew cellar with pattern {}", - cellar_glob + "No llvm-config found in brew cellar with pattern {cellar_glob}" )), } } diff --git a/libafl_concolic/symcc_runtime/build.rs b/libafl_concolic/symcc_runtime/build.rs index 11d6cc01b4..77fb8832d9 100644 --- a/libafl_concolic/symcc_runtime/build.rs +++ b/libafl_concolic/symcc_runtime/build.rs @@ -182,8 +182,7 @@ fn write_symcc_runtime_bindings_file(out_path: &Path, cpp_bindings: &bindgen::Bi let function_name = &captures[1]; writeln!( bindings_file, - "#[link_name=\"{}{}\"]", - SYMCC_RUNTIME_FUNCTION_NAME_PREFIX, function_name + "#[link_name=\"{SYMCC_RUNTIME_FUNCTION_NAME_PREFIX}{function_name}\"]" ) .unwrap(); } diff --git a/libafl_frida/src/alloc.rs b/libafl_frida/src/alloc.rs index 05554083e3..698ee61c99 100644 --- a/libafl_frida/src/alloc.rs +++ b/libafl_frida/src/alloc.rs @@ -440,8 +440,7 @@ impl Allocator { Some(metadata) => metadata.size, None => { panic!( - "Attempted to get_usable_size on a pointer ({:?}) which was not allocated!", - ptr + "Attempted to get_usable_size on a pointer ({ptr:?}) which was not allocated!" ); } } diff --git a/libafl_frida/src/asan/asan_rt.rs b/libafl_frida/src/asan/asan_rt.rs index b24b79d70b..52a2682e3b 100644 --- a/libafl_frida/src/asan/asan_rt.rs +++ b/libafl_frida/src/asan/asan_rt.rs @@ -399,8 +399,7 @@ impl AsanRuntime { self.allocator .map_shadow_for_region(tls_start, tls_end, true); println!( - "registering thread with stack {:x}:{:x} and tls {:x}:{:x}", - stack_start, stack_end, tls_start, tls_end + "registering thread with stack {stack_start:x}:{stack_end:x} and tls {tls_start:x}:{tls_end:x}" ); } @@ -1547,7 +1546,8 @@ impl AsanRuntime { } #[cfg(target_arch = "aarch64")] - #[allow(clippy::unused_self, clippy::identity_op)] // identity_op appears to be a false positive in ubfx + // identity_op appears to be a false positive in ubfx + #[allow(clippy::unused_self, clippy::identity_op, clippy::too_many_lines)] fn generate_shadow_check_function(&mut self) { let shadow_bit = self.allocator.shadow_bit(); let mut ops = dynasmrt::VecAssembler::::new(0); @@ -1657,8 +1657,9 @@ impl AsanRuntime { let mut map_flags = MapFlags::MAP_ANON | MapFlags::MAP_PRIVATE; // apple aarch64 requires MAP_JIT to allocates WX pages - #[cfg(all(target_vendor = "apple", target_arch = "aarch64"))] - map_flags |= MapFlags::MAP_JIT; + if cfg!(all(target_vendor = "apple", target_arch = "aarch64")) { + map_flags |= MapFlags::MAP_JIT; + } unsafe { let mapping = mmap( @@ -1678,7 +1679,7 @@ impl AsanRuntime { blob.as_ptr() .copy_to_nonoverlapping(mapping as *mut u8, blob.len()); - + #[cfg(all(target_vendor = "apple", target_arch = "aarch64"))] libc::pthread_jit_write_protect_np(1); self.shadow_check_func = Some(std::mem::transmute(mapping as *mut u8)); @@ -2047,19 +2048,16 @@ impl AsanRuntime { ; .qword addr_of_mut!(self.eh_frame) as i64 ); self.eh_frame = [ - 0x14, 0, 0x00527a01, 0x011e7c01, 0x001f0c1b, - // eh_frame_fde - 0x14, 0x18, - // fde_address - 0, // <-- address offset goes here - 0x104, + 0x14, 0, 0x00527a01, 0x011e7c01, 0x001f0c1b, // eh_frame_fde + 0x14, 0x18, // fde_address + 0, // <-- address offset goes here + 0x104, // advance_loc 12 // def_cfa r29 (x29) at offset 16 // offset r30 (x30) at cfa-8 // offset r29 (x29) at cfa-16 - 0x1d0c4c00, 0x9d029e10, 0x4, - // empty next FDE: - 0, 0 + 0x1d0c4c00, 0x9d029e10, 0x4, // empty next FDE: + 0, 0, ]; self.blob_report = Some(ops_report.finalize().unwrap().into_boxed_slice()); diff --git a/libafl_frida/src/asan/errors.rs b/libafl_frida/src/asan/errors.rs index e9846b0d39..00b6a8593c 100644 --- a/libafl_frida/src/asan/errors.rs +++ b/libafl_frida/src/asan/errors.rs @@ -312,8 +312,7 @@ impl AsanErrors { | AsanError::BadFuncArgWrite((name, _pc, address, size, backtrace)) => { writeln!( output, - " in call to {}, argument {:#016x}, size: {:#x}", - name, address, size + " in call to {name}, argument {address:#016x}, size: {size:#x}" ) .unwrap(); output.reset().unwrap(); @@ -432,12 +431,7 @@ impl AsanErrors { ) .unwrap(); } else { - writeln!( - output, - " at 0x{:x}, faulting address 0x{:x}", - pc, fault_address - ) - .unwrap(); + writeln!(output, " at 0x{pc:x}, faulting address 0x{fault_address:x}").unwrap(); } output.reset().unwrap(); diff --git a/libafl_qemu/libafl_qemu_build/src/build.rs b/libafl_qemu/libafl_qemu_build/src/build.rs index 43619ea774..d5d92813a2 100644 --- a/libafl_qemu/libafl_qemu_build/src/build.rs +++ b/libafl_qemu/libafl_qemu_build/src/build.rs @@ -69,10 +69,7 @@ pub fn build( } if !qemu_path.is_dir() { - println!( - "cargo:warning=Qemu not found, cloning with git ({})...", - QEMU_REVISION - ); + println!("cargo:warning=Qemu not found, cloning with git ({QEMU_REVISION})..."); fs::create_dir_all(&qemu_path).unwrap(); Command::new("git") .current_dir(&qemu_path) diff --git a/libafl_targets/build.rs b/libafl_targets/build.rs index eeb922459e..1d41cbf5ae 100644 --- a/libafl_targets/build.rs +++ b/libafl_targets/build.rs @@ -33,17 +33,16 @@ fn main() { "// These constants are autogenerated by build.rs /// The size of the edges map - pub const EDGES_MAP_SIZE: usize = {}; + pub const EDGES_MAP_SIZE: usize = {edges_map_size}; /// The size of the cmps map - pub const CMP_MAP_SIZE: usize = {}; + pub const CMP_MAP_SIZE: usize = {cmp_map_size}; /// The width of the `CmpLog` map - pub const CMPLOG_MAP_W: usize = {}; + pub const CMPLOG_MAP_W: usize = {cmplog_map_w}; /// The height of the `CmpLog` map - pub const CMPLOG_MAP_H: usize = {}; + pub const CMPLOG_MAP_H: usize = {cmplog_map_h}; /// The size of the accounting maps - pub const ACCOUNTING_MAP_SIZE: usize = {}; -", - edges_map_size, cmp_map_size, cmplog_map_w, cmplog_map_h, acc_map_size + pub const ACCOUNTING_MAP_SIZE: usize = {acc_map_size}; +" ) .expect("Could not write file"); From 710eb77079aaae14d850cf4f54adfc6dc578c372 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Sun, 4 Dec 2022 18:36:01 +0000 Subject: [PATCH 02/10] undo comment fmt --- libafl_frida/src/asan/asan_rt.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/libafl_frida/src/asan/asan_rt.rs b/libafl_frida/src/asan/asan_rt.rs index 52a2682e3b..353563983f 100644 --- a/libafl_frida/src/asan/asan_rt.rs +++ b/libafl_frida/src/asan/asan_rt.rs @@ -2048,15 +2048,18 @@ impl AsanRuntime { ; .qword addr_of_mut!(self.eh_frame) as i64 ); self.eh_frame = [ - 0x14, 0, 0x00527a01, 0x011e7c01, 0x001f0c1b, // eh_frame_fde - 0x14, 0x18, // fde_address - 0, // <-- address offset goes here + 0x14, 0, 0x00527a01, 0x011e7c01, 0x001f0c1b, // + // eh_frame_fde + 0x14, 0x18, // + // fde_address + 0, // <-- address offset goes here 0x104, // advance_loc 12 // def_cfa r29 (x29) at offset 16 // offset r30 (x30) at cfa-8 // offset r29 (x29) at cfa-16 - 0x1d0c4c00, 0x9d029e10, 0x4, // empty next FDE: + 0x1d0c4c00, 0x9d029e10, 0x4, // + // empty next FDE: 0, 0, ]; From 43df081f731e9f3877b3aedd6a6b4f2712dbe847 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Sun, 4 Dec 2022 18:43:16 +0000 Subject: [PATCH 03/10] add unstracked nyx files to gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 4fcea77629..9a6553edf8 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,6 @@ __pycache__ **/libxml2 **/corpus_discovered **/libxml2-*.tar.gz + +libafl_nyx/QEMU-Nyx +libafl_nyx/packer \ No newline at end of file From c4bbc5dc356b3fefefeb1eb892923fd32e12ba54 Mon Sep 17 00:00:00 2001 From: tokatoka Date: Mon, 5 Dec 2022 20:37:27 +0900 Subject: [PATCH 04/10] fix --- libafl/src/events/simple.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libafl/src/events/simple.rs b/libafl/src/events/simple.rs index d435b74db9..9498d95edf 100644 --- a/libafl/src/events/simple.rs +++ b/libafl/src/events/simple.rs @@ -444,7 +444,7 @@ where // We start ourself as child process to actually fuzz let mut staterestorer = if std::env::var(_ENV_FUZZER_SENDER).is_err() { // First, create a place to store state in, for restarts. - let staterestorer: StateRestorer = + let mut staterestorer: StateRestorer = StateRestorer::new(shmem_provider.new_shmem(256 * 1024 * 1024)?); //let staterestorer = { LlmpSender::new(shmem_provider.clone(), 0, false)? }; staterestorer.write_to_env(_ENV_FUZZER_SENDER)?; From 2e8240d0ff938e7d46d3339911e5c862825906c2 Mon Sep 17 00:00:00 2001 From: tokatoka Date: Mon, 5 Dec 2022 20:40:57 +0900 Subject: [PATCH 05/10] windows, no_std --- libafl/src/bolts/llmp.rs | 3 +-- libafl/src/events/simple.rs | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libafl/src/bolts/llmp.rs b/libafl/src/bolts/llmp.rs index 3d81657c54..d423e4e675 100644 --- a/libafl/src/bolts/llmp.rs +++ b/libafl/src/bolts/llmp.rs @@ -2405,8 +2405,7 @@ where println!("Error adding client! Ignoring: {e:?}"); #[cfg(not(feature = "std"))] return Err(Error::unknown(format!( - "Error adding client! PANIC! {:?}", - e + "Error adding client! PANIC! {e:?}" ))); } }; diff --git a/libafl/src/events/simple.rs b/libafl/src/events/simple.rs index 9498d95edf..bedbdcd92c 100644 --- a/libafl/src/events/simple.rs +++ b/libafl/src/events/simple.rs @@ -444,8 +444,13 @@ where // We start ourself as child process to actually fuzz let mut staterestorer = if std::env::var(_ENV_FUZZER_SENDER).is_err() { // First, create a place to store state in, for restarts. + #[cfg(unix)] let mut staterestorer: StateRestorer = StateRestorer::new(shmem_provider.new_shmem(256 * 1024 * 1024)?); + #[cfg(windows)] + let staterestorer: StateRestorer = + StateRestorer::new(shmem_provider.new_shmem(256 * 1024 * 1024)?); + //let staterestorer = { LlmpSender::new(shmem_provider.clone(), 0, false)? }; staterestorer.write_to_env(_ENV_FUZZER_SENDER)?; From 11f123f6c905454d162b5e9fe10c7e26de68dbc4 Mon Sep 17 00:00:00 2001 From: tokatoka Date: Mon, 5 Dec 2022 20:41:56 +0900 Subject: [PATCH 06/10] fix --- libafl/src/events/simple.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libafl/src/events/simple.rs b/libafl/src/events/simple.rs index bedbdcd92c..2259392544 100644 --- a/libafl/src/events/simple.rs +++ b/libafl/src/events/simple.rs @@ -447,7 +447,7 @@ where #[cfg(unix)] let mut staterestorer: StateRestorer = StateRestorer::new(shmem_provider.new_shmem(256 * 1024 * 1024)?); - #[cfg(windows)] + #[cfg(not(windows))] let staterestorer: StateRestorer = StateRestorer::new(shmem_provider.new_shmem(256 * 1024 * 1024)?); From 420bf525ae471a28e488ff64cc000cd667d78021 Mon Sep 17 00:00:00 2001 From: tokatoka Date: Mon, 5 Dec 2022 20:42:19 +0900 Subject: [PATCH 07/10] fix --- libafl/src/events/simple.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libafl/src/events/simple.rs b/libafl/src/events/simple.rs index 2259392544..43c4ad5880 100644 --- a/libafl/src/events/simple.rs +++ b/libafl/src/events/simple.rs @@ -447,7 +447,7 @@ where #[cfg(unix)] let mut staterestorer: StateRestorer = StateRestorer::new(shmem_provider.new_shmem(256 * 1024 * 1024)?); - #[cfg(not(windows))] + #[cfg(not(unix))] let staterestorer: StateRestorer = StateRestorer::new(shmem_provider.new_shmem(256 * 1024 * 1024)?); From 4cee6be99209e129674cba053ad224d4f85e26ea Mon Sep 17 00:00:00 2001 From: tokatoka Date: Mon, 5 Dec 2022 20:53:27 +0900 Subject: [PATCH 08/10] more --- libafl/src/events/llmp.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libafl/src/events/llmp.rs b/libafl/src/events/llmp.rs index 365031aa17..a36f586e20 100644 --- a/libafl/src/events/llmp.rs +++ b/libafl/src/events/llmp.rs @@ -887,8 +887,13 @@ where mgr.to_env(_ENV_FUZZER_BROKER_CLIENT_INITIAL); // First, create a channel from the current fuzzer to the next to store state between restarts. + #[cfg(unix)] let mut staterestorer: StateRestorer = StateRestorer::new(self.shmem_provider.new_shmem(256 * 1024 * 1024)?); + + #[cfg(not(unix))] + let staterestorer: StateRestorer = + StateRestorer::new(self.shmem_provider.new_shmem(256 * 1024 * 1024)?); // Store the information to a map. staterestorer.write_to_env(_ENV_FUZZER_SENDER)?; From 4f2207a3a2f7ec2d42389297065c34fe3414c527 Mon Sep 17 00:00:00 2001 From: tokatoka Date: Mon, 5 Dec 2022 21:30:21 +0900 Subject: [PATCH 09/10] macos --- libafl/src/bolts/core_affinity.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libafl/src/bolts/core_affinity.rs b/libafl/src/bolts/core_affinity.rs index 9c32c41438..a59e1da8c6 100644 --- a/libafl/src/bolts/core_affinity.rs +++ b/libafl/src/bolts/core_affinity.rs @@ -590,8 +590,7 @@ mod apple { Ok(()) } else { Err(Error::unknown(format!( - "Failed to set_for_current {:?}", - result + "Failed to set_for_current {result:?}" ))) } } From 38fdd3785332ffa635a1d7bfba50935640869f3c Mon Sep 17 00:00:00 2001 From: tokatoka Date: Mon, 5 Dec 2022 21:57:55 +0900 Subject: [PATCH 10/10] remove doctest --- libafl/src/observers/value.rs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/libafl/src/observers/value.rs b/libafl/src/observers/value.rs index 41c87b66ea..d5a0d6a461 100644 --- a/libafl/src/observers/value.rs +++ b/libafl/src/observers/value.rs @@ -46,36 +46,17 @@ where } /// Get a reference to the underlying value. - /// - /// ``` - /// # use libafl::observers::value::ValueObserver; - /// let mut obs = ValueObserver::new("example", &2); - /// assert_eq!(&2, obs.get_ref()); - /// ``` #[must_use] pub fn get_ref(&self) -> &T { self.value.as_ref() } /// Set the value. - /// - /// ``` - /// # use libafl::observers::value::ValueObserver; - /// let mut obs = ValueObserver::new("example", &2); - /// obs.set(3); - /// assert_eq!(3, obs.take()); - /// ``` pub fn set(&mut self, new_value: T) { self.value = OwnedRef::Owned(Box::new(new_value)); } /// Clone or move the current value out of this object. - /// - /// ``` - /// # use libafl::observers::value::ValueObserver; - /// let mut obs = ValueObserver::new("example", &2); - /// assert_eq!(2, obs.take()); - /// ``` #[must_use] pub fn take(self) -> T where