From c863c8bd6ca6ecbfeebd13968f25536e2e85dbb3 Mon Sep 17 00:00:00 2001 From: Romain Malmain Date: Mon, 24 Mar 2025 15:03:04 +0100 Subject: [PATCH] Fix clippy (#3102) * fix clippy * libafl_frida/ * lol * lol --------- Co-authored-by: Toka --- Cargo.toml | 1 + libafl/src/events/centralized.rs | 3 +-- libafl/src/events/llmp/restarting.rs | 2 +- libafl/src/executors/forkserver.rs | 5 +---- libafl/src/executors/hooks/inprocess.rs | 2 +- libafl/src/executors/hooks/unix.rs | 4 ++-- libafl/src/mutators/token_mutations.rs | 4 ++-- libafl/src/stages/sync.rs | 4 ++-- libafl/src/state/mod.rs | 5 +---- libafl_bolts/src/lib.rs | 2 +- libafl_bolts/src/llmp.rs | 13 ++++++------- libafl_bolts/src/os/windows_exceptions.rs | 2 +- libafl_bolts/src/shmem.rs | 18 ++++++++---------- libafl_frida/src/allocator.rs | 8 ++++---- libafl_frida/src/asan/asan_rt.rs | 13 +++++-------- libafl_frida/src/asan/hook_funcs.rs | 2 +- libafl_frida/src/executor.rs | 2 +- libafl_frida/src/helper.rs | 2 +- libafl_frida/src/lib.rs | 2 +- libafl_frida/src/pthread_hook.rs | 2 +- libafl_intelpt/src/linux.rs | 3 +-- libafl_qemu/src/executor.rs | 2 +- libafl_qemu/src/modules/usermode/snapshot.rs | 4 ++-- libafl_targets/src/sancov_pcguard.rs | 2 +- 24 files changed, 47 insertions(+), 60 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 48ae85af14..b2620d8e08 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -173,6 +173,7 @@ similar_names = "allow" too_many_lines = "allow" comparison_chain = "allow" # This lint makes **ZERO** sense unnecessary_debug_formatting = "allow" # :thumbsdown: :thumbsdown: :thumbsdown: :thumbsdown: :thumbsdown: :thumbsdown: +struct_field_names = "allow" # ???? [workspace.lints.rustdoc] # Deny diff --git a/libafl/src/events/centralized.rs b/libafl/src/events/centralized.rs index cbc267b040..320de93ebe 100644 --- a/libafl/src/events/centralized.rs +++ b/libafl/src/events/centralized.rs @@ -405,8 +405,7 @@ where .. } => { log::debug!( - "Received {} from {client_id:?} ({client_config:?}, forward {forward_id:?})", - event_name + "Received {event_name} from {client_id:?} ({client_config:?}, forward {forward_id:?})" ); log::debug!( diff --git a/libafl/src/events/llmp/restarting.rs b/libafl/src/events/llmp/restarting.rs index a453979b75..d1f4738772 100644 --- a/libafl/src/events/llmp/restarting.rs +++ b/libafl/src/events/llmp/restarting.rs @@ -561,7 +561,7 @@ where // Send this mesasge off and we are leaving. match send_tcp_msg(&mut stream, &msg) { Ok(()) => (), - Err(e) => log::error!("Failed to send tcp message {:#?}", e), + Err(e) => log::error!("Failed to send tcp message {e:#?}"), } log::debug!("Asking he broker to be disconnected"); Ok(()) diff --git a/libafl/src/executors/forkserver.rs b/libafl/src/executors/forkserver.rs index 9d00b8e2d0..064d07932a 100644 --- a/libafl/src/executors/forkserver.rs +++ b/libafl/src/executors/forkserver.rs @@ -1039,10 +1039,7 @@ where ))); } - log::info!( - "All right - new fork server model version {} is up", - version - ); + log::info!("All right - new fork server model version {version} is up"); let status = forkserver.read_st().map_err(|err| { Error::illegal_state(format!("Reading from forkserver failed: {err:?}")) diff --git a/libafl/src/executors/hooks/inprocess.rs b/libafl/src/executors/hooks/inprocess.rs index 0880538efe..8bb1b835cc 100644 --- a/libafl/src/executors/hooks/inprocess.rs +++ b/libafl/src/executors/hooks/inprocess.rs @@ -505,7 +505,7 @@ impl InProcessExecutorHandlerData { if let Ok(bsod) = bsod { if let Ok(r) = core::str::from_utf8(&bsod) { - log::error!("{}", r); + log::error!("{r}"); } } } diff --git a/libafl/src/executors/hooks/unix.rs b/libafl/src/executors/hooks/unix.rs index 41f01b94d1..93cf205c3e 100644 --- a/libafl/src/executors/hooks/unix.rs +++ b/libafl/src/executors/hooks/unix.rs @@ -247,7 +247,7 @@ pub mod unix_signal_handler { let _ = writer.flush(); } if let Ok(r) = core::str::from_utf8(&bsod) { - log::error!("{}", r); + log::error!("{r}"); } } @@ -287,7 +287,7 @@ pub mod unix_signal_handler { let _ = writer.flush(); } if let Ok(r) = core::str::from_utf8(&bsod) { - log::error!("{}", r); + log::error!("{r}"); } } } diff --git a/libafl/src/mutators/token_mutations.rs b/libafl/src/mutators/token_mutations.rs index 58df249555..53f41ce4cb 100644 --- a/libafl/src/mutators/token_mutations.rs +++ b/libafl/src/mutators/token_mutations.rs @@ -450,7 +450,7 @@ where let Some(meta) = state.metadata_map().get::() else { return Ok(MutationResult::Skipped); }; - log::trace!("meta: {:x?}", meta); + log::trace!("meta: {meta:x?}"); meta.list.len() }; @@ -648,7 +648,7 @@ where let Some(meta) = state.metadata_map().get::() else { return Ok(MutationResult::Skipped); }; - log::trace!("meta: {:x?}", meta); + log::trace!("meta: {meta:x?}"); let Some(cmps_len) = NonZero::new(meta.list.len()) else { return Ok(MutationResult::Skipped); diff --git a/libafl/src/stages/sync.rs b/libafl/src/stages/sync.rs index 8b2d3fbdb4..0980278c69 100644 --- a/libafl/src/stages/sync.rs +++ b/libafl/src/stages/sync.rs @@ -107,7 +107,7 @@ where let mut new_files = vec![]; for dir in &self.sync_dirs { - log::debug!("Syncing from dir: {:?}", dir); + log::debug!("Syncing from dir: {dir:?}"); let new_dir_files = find_new_files_rec(dir, &last)?; new_files.extend(new_dir_files); } @@ -134,7 +134,7 @@ where .unwrap() .left_to_sync .retain(|p| p != &path); - log::debug!("Syncing and evaluating {:?}", path); + log::debug!("Syncing and evaluating {path:?}"); fuzzer.evaluate_input(state, executor, manager, &input)?; } diff --git a/libafl/src/state/mod.rs b/libafl/src/state/mod.rs index 4308e192bf..61ee7da269 100644 --- a/libafl/src/state/mod.rs +++ b/libafl/src/state/mod.rs @@ -977,10 +977,7 @@ where self.reset_initial_files_state(); self.canonicalize_input_dirs(in_dirs)?; if cores.ids.len() > corpus_size { - log::info!( - "low intial corpus count ({}), no parallelism required.", - corpus_size - ); + log::info!("low intial corpus count ({corpus_size}), no parallelism required."); } else { let core_index = cores .ids diff --git a/libafl_bolts/src/lib.rs b/libafl_bolts/src/lib.rs index 79911f5b11..d3204fce8e 100644 --- a/libafl_bolts/src/lib.rs +++ b/libafl_bolts/src/lib.rs @@ -1106,7 +1106,7 @@ mod windows_logging { // Get the handle to standard output let h_stdout: HANDLE = get_stdout_handle(); - if h_stdout == INVALID_HANDLE_VALUE { + if ptr::eq(h_stdout, INVALID_HANDLE_VALUE) { eprintln!("Failed to get standard output handle"); return; } diff --git a/libafl_bolts/src/llmp.rs b/libafl_bolts/src/llmp.rs index d51a81be56..3b6867df33 100644 --- a/libafl_bolts/src/llmp.rs +++ b/libafl_bolts/src/llmp.rs @@ -1587,7 +1587,7 @@ where unsafe { // log::info!("Sending msg {:?}", msg); - assert!(self.last_msg_sent != msg, "Message sent twice!"); + assert!(!ptr::eq(self.last_msg_sent, msg), "Message sent twice!"); assert!( (*msg).tag != LLMP_TAG_UNSET, "No tag set on message with id {:?}", @@ -2276,7 +2276,7 @@ impl SignalHandler for LlmpShutdownSignalHandler { #[cfg(all(windows, feature = "std"))] impl CtrlHandler for LlmpShutdownSignalHandler { fn handle(&mut self, ctrl_type: u32) -> bool { - log::info!("LLMP: Received shutdown signal, ctrl_type {:?}", ctrl_type); + log::info!("LLMP: Received shutdown signal, ctrl_type {ctrl_type:?}"); unsafe { ptr::write_volatile(&mut self.shutting_down, true); } @@ -2421,7 +2421,7 @@ impl Brokers { } else { log::info!( "{}: Broker successfully setup control handlers", - std::process::id().to_string() + std::process::id() ); } } @@ -2694,7 +2694,7 @@ where for idx in (0..self.inner.llmp_clients.len()).rev() { let client_id = self.inner.llmp_clients[idx].id; if self.inner.clients_to_remove.contains(&client_id) { - log::info!("Client {:#?} wants to exit. Removing.", client_id); + log::info!("Client {client_id:#?} wants to exit. Removing."); self.inner.llmp_clients.remove(idx); } } @@ -2777,8 +2777,7 @@ where let exitinfo = (*msg).buf.as_mut_ptr() as *mut LlmpClientExitInfo; let client_id = ClientId((*exitinfo).client_id); log::info!( - "Client exit message received!, we are removing clients whose client_group_id is {:#?}", - client_id + "Client exit message received!, we are removing clients whose client_group_id is {client_id:#?}" ); self.inner.clients_to_remove.push(client_id); @@ -2890,7 +2889,7 @@ where } else { log::info!( "{}: Broker successfully setup control handlers", - std::process::id().to_string() + std::process::id() ); } } diff --git a/libafl_bolts/src/os/windows_exceptions.rs b/libafl_bolts/src/os/windows_exceptions.rs index 52d7d7f2fd..0bac219200 100644 --- a/libafl_bolts/src/os/windows_exceptions.rs +++ b/libafl_bolts/src/os/windows_exceptions.rs @@ -508,7 +508,7 @@ pub unsafe extern "system" fn handle_exception( .ExceptionCode }; let exception_code = From::from(code.0); - log::info!("Received exception; code: {}", exception_code); + log::info!("Received exception; code: {exception_code}"); unsafe { internal_handle_exception(exception_code, exception_pointers) } } diff --git a/libafl_bolts/src/shmem.rs b/libafl_bolts/src/shmem.rs index 8780abba3e..36013556f1 100644 --- a/libafl_bolts/src/shmem.rs +++ b/libafl_bolts/src/shmem.rs @@ -771,7 +771,7 @@ pub mod unix_shmem { shm_fd, 0, ); - if map == libc::MAP_FAILED || map.is_null() { + if ptr::eq(map, libc::MAP_FAILED) { close(shm_fd); shm_unlink(filename_path.as_ptr() as *const _); return Err(Error::last_os_error(format!( @@ -845,7 +845,7 @@ pub mod unix_shmem { shm_fd, 0, ); - if map == libc::MAP_FAILED || map.is_null() { + if ptr::eq(map, libc::MAP_FAILED) { close(shm_fd); return Err(Error::last_os_error(format!( "mmap() failed for map with fd {shm_fd:?}" @@ -1081,7 +1081,7 @@ pub mod unix_shmem { let id_int: i32 = id.into(); let map = shmat(id_int, ptr::null(), 0) as *mut c_uchar; - if map.is_null() || map == ptr::null_mut::().wrapping_sub(1) { + if ptr::eq(map, ptr::null_mut::().wrapping_sub(1)) { return Err(Error::last_os_error(format!( "Failed to map the shared mapping with id {id_int}" ))); @@ -1250,7 +1250,7 @@ pub mod unix_shmem { fd, 0, ); - if map == usize::MAX as *mut c_void { + if ptr::eq(map, usize::MAX as *mut c_void) { close(fd); return Err(Error::unknown( "Failed to map the ashmem mapping".to_string(), @@ -1285,7 +1285,7 @@ pub mod unix_shmem { fd, 0, ); - if map == usize::MAX as *mut c_void { + if ptr::eq(map, usize::MAX as *mut c_void) { close(fd); return Err(Error::unknown( "Failed to map the ashmem mapping".to_string(), @@ -1392,9 +1392,7 @@ pub mod unix_shmem { }; use std::os::fd::IntoRawFd; - use libc::{ - MAP_SHARED, PROT_READ, PROT_WRITE, c_void, close, fstat, ftruncate, mmap, munmap, - }; + use libc::{MAP_SHARED, PROT_READ, PROT_WRITE, close, fstat, ftruncate, mmap, munmap}; use nix::sys::memfd::{MemFdCreateFlag, memfd_create}; use crate::{ @@ -1436,7 +1434,7 @@ pub mod unix_shmem { fd, 0, ); - if map == usize::MAX as *mut c_void { + if ptr::eq(map, libc::MAP_FAILED) { close(fd); return Err(Error::unknown( "Failed to map the memfd mapping".to_string(), @@ -1473,7 +1471,7 @@ pub mod unix_shmem { fd, 0, ); - if map == usize::MAX as *mut c_void { + if ptr::eq(map, libc::MAP_FAILED) { return Err(Error::last_os_error(format!( "mmap() failed for map with fd {fd:?}" ))); diff --git a/libafl_frida/src/allocator.rs b/libafl_frida/src/allocator.rs index 161ee59aa2..eafef0b1af 100644 --- a/libafl_frida/src/allocator.rs +++ b/libafl_frida/src/allocator.rs @@ -594,7 +594,7 @@ impl Allocator { .any(|r| r.start <= start && r.end >= start + size); if !valid { - log::error!("Not a valid shadow: {:#x}!", start); + log::error!("Not a valid shadow: {start:#x}!"); } valid } @@ -720,7 +720,7 @@ impl Allocator { &mut |range: &RangeDetails| -> bool { let start = range.memory_range().base_address().0 as usize; let end = start + range.memory_range().size(); - log::trace!("New range: {:#x}-{:#x}", start, end); + log::trace!("New range: {start:#x}-{end:#x}"); #[cfg(target_vendor = "apple")] if start >= 0x600000000000 { @@ -762,7 +762,7 @@ impl Allocator { } } - log::trace!("max bit: {}", maxbit); + log::trace!("max bit: {maxbit}"); { for try_shadow_bit in 44..=maxbit { @@ -773,7 +773,7 @@ impl Allocator { // check if the proposed shadow bit overlaps with occupied ranges. for (start, end) in &occupied_ranges { if (shadow_start <= *end) && (*start <= shadow_end) { - log::trace!("{:x} {:x}, {:x} {:x}", shadow_start, shadow_end, start, end); + log::trace!("{shadow_start:x} {shadow_end:x}, {start:x} {end:x}"); log::warn!("shadow_bit {try_shadow_bit:} is not suitable"); good_candidate = false; break; diff --git a/libafl_frida/src/asan/asan_rt.rs b/libafl_frida/src/asan/asan_rt.rs index 621b2373de..2312b8cd78 100644 --- a/libafl_frida/src/asan/asan_rt.rs +++ b/libafl_frida/src/asan/asan_rt.rs @@ -527,10 +527,7 @@ impl AsanRuntime { }); if start == 0 { - log::error!( - "range_for_address: no range found for address {:#x}", - address - ); + log::error!("range_for_address: no range found for address {address:#x}"); } (start, end) } @@ -1529,7 +1526,7 @@ impl AsanRuntime { let insn = instructions[0]; // This is the very instruction that has triggered fault log::info!( "Fault Instruction: {}", - insn.display_with(DisplayStyle::Intel).to_string() + insn.display_with(DisplayStyle::Intel) ); let operand_count = insn.operand_count(); @@ -2478,7 +2475,7 @@ impl AsanRuntime { let result = frida_to_cs(decoder, instr); if let Err(e) = result { - log::error!("{}", e); + log::error!("{e}"); return None; } @@ -2520,7 +2517,7 @@ impl AsanRuntime { // println!("{:#?} {:#?} {:#?}", cs_instr, cs_instr.to_string(), operand); // println!("{:#?}", (memsz, basereg, indexreg, scale, disp)); - log::trace!("ASAN Interesting operand {:#?}", operand); + log::trace!("ASAN Interesting operand {operand:#?}"); log::trace!("{:#?}", (memsz, basereg, indexreg, scale, disp)); return Some((memsz, basereg, indexreg, scale, disp)); } @@ -2699,7 +2696,7 @@ impl AsanRuntime { writer.put_nop(); } } else { - log::trace!("Cannot check instructions for {:?} bytes.", width); + log::trace!("Cannot check instructions for {width:?} bytes."); } writer.put_pop_reg(X86Register::Rdi); diff --git a/libafl_frida/src/asan/hook_funcs.rs b/libafl_frida/src/asan/hook_funcs.rs index 8db66e7fb0..b40b38e2ac 100644 --- a/libafl_frida/src/asan/hook_funcs.rs +++ b/libafl_frida/src/asan/hook_funcs.rs @@ -1608,7 +1608,7 @@ impl AsanRuntime { ) -> *mut c_void { log::trace!("hook_mmap"); let res = original(addr, length, prot, flags, fd, offset); - if res != (-1_isize as *mut c_void) { + if !ptr::eq(res, -1_isize as *mut c_void) { self.allocator_mut() .map_shadow_for_region(res as usize, res as usize + length, true); } diff --git a/libafl_frida/src/executor.rs b/libafl_frida/src/executor.rs index 709580054c..7dc15130bb 100644 --- a/libafl_frida/src/executor.rs +++ b/libafl_frida/src/executor.rs @@ -101,7 +101,7 @@ where // so that Stalker knows to pick it despite the module being excluded let harness_fn_ref: &H = self.base.harness(); let ptr: *const H = harness_fn_ref as *const H; - log::info!("Activating Stalker for {:p}", ptr); + log::info!("Activating Stalker for {ptr:p}"); self.stalker.activate(NativePointer(ptr as *mut c_void)); } let res = self.base.run_target(fuzzer, state, mgr, input); diff --git a/libafl_frida/src/helper.rs b/libafl_frida/src/helper.rs index 8ba75b2a9e..9846d740e5 100644 --- a/libafl_frida/src/helper.rs +++ b/libafl_frida/src/helper.rs @@ -460,7 +460,7 @@ impl FridaInstrumentationHelperBuilder { .remove(range.start as u64..range.end as u64), SkipRange::ModuleRelative { name, range } => { if name.eq(&module.name()) { - log::trace!("Skipping {:?} {:?}", name, range); + log::trace!("Skipping {name:?} {range:?}"); let module_details = Module::load(gum, &name.to_string()); let lib_start = module_details.range().base_address().0 as u64; ranges.borrow_mut().remove( diff --git a/libafl_frida/src/lib.rs b/libafl_frida/src/lib.rs index 4c04f7efbf..74c5337086 100644 --- a/libafl_frida/src/lib.rs +++ b/libafl_frida/src/lib.rs @@ -443,7 +443,7 @@ mod tests { // Run the tests for each function for test in tests { let (function_name, expected_error) = test; - log::info!("Testing with harness function {}", function_name); + log::info!("Testing with harness function {function_name}"); let mut corpus = InMemoryCorpus::::new(); diff --git a/libafl_frida/src/pthread_hook.rs b/libafl_frida/src/pthread_hook.rs index 9b9b579640..8532cc191a 100644 --- a/libafl_frida/src/pthread_hook.rs +++ b/libafl_frida/src/pthread_hook.rs @@ -170,7 +170,7 @@ where let prev = unsafe { pthread_introspection_hook_install(pthread_introspection_hook as _) }; // Allow because we're sure this isn't from a different code generation unit. - if !(prev).is_null() && prev != pthread_introspection_hook as _ { + if !(prev).is_null() && !core::ptr::eq(prev, pthread_introspection_hook as _) { unsafe { (*previous_hook_ptr_mut()).set(prev as *const pthread_introspection_hook_t); } diff --git a/libafl_intelpt/src/linux.rs b/libafl_intelpt/src/linux.rs index 17bd6e1511..a5ce4243d7 100644 --- a/libafl_intelpt/src/linux.rs +++ b/libafl_intelpt/src/linux.rs @@ -471,8 +471,7 @@ impl IntelPT { if e.code() != PtErrorCode::Eos { let offset = decoder.offset().map_err(error_from_pt_error)?; log::info!( - "PT error in block next {e:?} trace offset {offset:x} last decoded block end {:x}", - previous_block_end_ip + "PT error in block next {e:?} trace offset {offset:x} last decoded block end {previous_block_end_ip:x}" ); } break 'block; diff --git a/libafl_qemu/src/executor.rs b/libafl_qemu/src/executor.rs index c89bf39476..c76004400a 100644 --- a/libafl_qemu/src/executor.rs +++ b/libafl_qemu/src/executor.rs @@ -145,7 +145,7 @@ pub unsafe fn inproc_qemu_crash_handler( if let Ok(bsod) = bsod { if let Ok(bsod_str) = str::from_utf8(&bsod) { - log::error!("\n{}", bsod_str); + log::error!("\n{bsod_str}"); } else { log::error!("convert minibsod to string failed"); } diff --git a/libafl_qemu/src/modules/usermode/snapshot.rs b/libafl_qemu/src/modules/usermode/snapshot.rs index 9dfb6fb3a2..177abda037 100644 --- a/libafl_qemu/src/modules/usermode/snapshot.rs +++ b/libafl_qemu/src/modules/usermode/snapshot.rs @@ -383,7 +383,7 @@ impl SnapshotModule { } } } else { - log::warn!("\tpage not found @addr 0x{:x}", addr); + log::warn!("\tpage not found @addr 0x{addr:x}"); } addr += SNAPSHOT_PAGE_SIZE as GuestAddr; @@ -963,7 +963,7 @@ where } SYS_brk => { // We don't handle brk here. It is handled in the reset function only when it's needed. - log::debug!("New brk ({:#x?}) received.", result); + log::debug!("New brk ({result:#x?}) received."); } // mmap syscalls sys_const => { diff --git a/libafl_targets/src/sancov_pcguard.rs b/libafl_targets/src/sancov_pcguard.rs index 4001f71490..e01abd2a5f 100644 --- a/libafl_targets/src/sancov_pcguard.rs +++ b/libafl_targets/src/sancov_pcguard.rs @@ -266,7 +266,7 @@ pub unsafe extern "C" fn __sanitizer_cov_trace_pc_guard_init(mut start: *mut u32 EDGES_MAP_PTR = &raw mut EDGES_MAP as *mut u8; } - if start == stop || *start != 0 { + if core::ptr::eq(start, stop) || *start != 0 { return; }