diff --git a/libafl/src/lib.rs b/libafl/src/lib.rs index 2d7388a5f6..019acd0594 100644 --- a/libafl/src/lib.rs +++ b/libafl/src/lib.rs @@ -29,8 +29,7 @@ Welcome to `LibAFL` clippy::ptr_cast_constness, clippy::unsafe_derive_deserialize, clippy::similar_names, - clippy::too_many_lines, - clippy::missing_transmute_annotations + clippy::too_many_lines )] #![cfg_attr(not(test), warn( missing_debug_implementations, diff --git a/libafl_bolts/src/lib.rs b/libafl_bolts/src/lib.rs index 564ca345d5..9501095a5d 100644 --- a/libafl_bolts/src/lib.rs +++ b/libafl_bolts/src/lib.rs @@ -30,8 +30,7 @@ clippy::module_name_repetitions, clippy::ptr_cast_constness, clippy::negative_feature_names, - clippy::too_many_lines, - clippy::missing_transmute_annotations + clippy::too_many_lines )] #![cfg_attr(not(test), warn( missing_debug_implementations, diff --git a/libafl_bolts/src/llmp.rs b/libafl_bolts/src/llmp.rs index 96545552e7..3cf6fce245 100644 --- a/libafl_bolts/src/llmp.rs +++ b/libafl_bolts/src/llmp.rs @@ -2492,6 +2492,7 @@ where } /// Tell the broker to disconnect this client from it. + #[cfg(feature = "std")] fn announce_client_exit(sender: &mut LlmpSender, client_id: u32) -> Result<(), Error> { unsafe { let msg = sender diff --git a/libafl_bolts/src/tuples.rs b/libafl_bolts/src/tuples.rs index f37bf3c0ea..a0c690d046 100644 --- a/libafl_bolts/src/tuples.rs +++ b/libafl_bolts/src/tuples.rs @@ -6,6 +6,7 @@ use alloc::vec::Vec; use core::any::type_name; use core::{ any::TypeId, + mem::transmute, ptr::{addr_of, addr_of_mut}, }; @@ -272,10 +273,7 @@ where fn take<'a, T: 'static>(mut self) -> (Option<&'a T>, Self) { if TypeId::of::() == TypeId::of::() { let r = self.0.take(); - ( - unsafe { core::mem::transmute::, Option<&T>>(r) }, - self, - ) + (unsafe { transmute::, Option<&T>>(r) }, self) } else { let (r, tail) = self.1.take::(); (r, (self.0, tail)) @@ -292,7 +290,7 @@ where if TypeId::of::() == TypeId::of::() { let r = self.0.take(); ( - unsafe { core::mem::transmute::, Option<&T>>(r) }, + unsafe { transmute::, Option<&T>>(r) }, self, ) } else { @@ -323,7 +321,7 @@ where if TypeId::of::() == TypeId::of::() { let r = self.0.take(); ( - unsafe { core::mem::transmute::, Option<&mut T>>(r) }, + unsafe { transmute::, Option<&mut T>>(r) }, self, ) } else { diff --git a/libafl_cc/src/lib.rs b/libafl_cc/src/lib.rs index 448963c446..d81e038721 100644 --- a/libafl_cc/src/lib.rs +++ b/libafl_cc/src/lib.rs @@ -13,8 +13,7 @@ clippy::missing_panics_doc, clippy::missing_docs_in_private_items, clippy::module_name_repetitions, - clippy::unreadable_literal, - clippy::missing_transmute_annotations + clippy::unreadable_literal )] #![cfg_attr(not(test), warn( missing_debug_implementations, diff --git a/libafl_frida/src/asan/asan_rt.rs b/libafl_frida/src/asan/asan_rt.rs index 64aa5f4626..3a69f72d6c 100644 --- a/libafl_frida/src/asan/asan_rt.rs +++ b/libafl_frida/src/asan/asan_rt.rs @@ -1533,7 +1533,10 @@ impl AsanRuntime { .unwrap(); blob.as_ptr() .copy_to_nonoverlapping(mapping as *mut u8, blob.len()); - self.shadow_check_func = Some(std::mem::transmute(mapping as *mut u8)); + self.shadow_check_func = Some(std::mem::transmute::< + *mut u8, + extern "C" fn(*const c_void, usize) -> bool, + >(mapping as *mut u8)); } } @@ -1680,7 +1683,10 @@ impl AsanRuntime { { libc::pthread_jit_write_protect_np(1); } - self.shadow_check_func = Some(std::mem::transmute(mapping as *mut u8)); + self.shadow_check_func = Some(std::mem::transmute::< + *mut u8, + extern "C" fn(*const c_void, usize) -> bool, + >(mapping as *mut u8)); } } diff --git a/libafl_frida/src/cmplog_rt.rs b/libafl_frida/src/cmplog_rt.rs index ac47156ae1..3970cb8afe 100644 --- a/libafl_frida/src/cmplog_rt.rs +++ b/libafl_frida/src/cmplog_rt.rs @@ -746,7 +746,7 @@ impl CmpLogRuntime { } #[cfg(all(feature = "cmplog", target_arch = "aarch64"))] - #[allow(clippy::similar_names)] + #[allow(clippy::similar_names, clippy::type_complexity)] #[inline] /// Check if the current instruction is cmplog relevant one(any opcode which sets the flags) #[must_use] @@ -765,7 +765,7 @@ impl CmpLogRuntime { .operands .iter() .position(|item| *item == Operand::Nothing) - .unwrap_or_else(|| 4); + .unwrap_or(4); // "cmp" | "ands" | "subs" | "adds" | "negs" | "ngcs" | "sbcs" | "bics" | "cbz" // | "cbnz" | "tbz" | "tbnz" | "adcs" - yaxpeax aliases insns (i.e., cmp -> subs) // We only care for compare instructions - aka instructions which set the flags @@ -846,14 +846,14 @@ impl CmpLogRuntime { None, )), Operand::ImmShift(imm, shift) => { - Some((CmplogOperandType::Imm((imm as u64) << shift), None)) + Some((CmplogOperandType::Imm(u64::from(imm) << shift), None)) } //precalculate the shift Operand::RegShift(shiftstyle, amount, regsize, reg) => { let reg = CmplogOperandType::Regid(writer_register(reg, regsize, true)); let shift = (shiftstyle, amount); Some((reg, Some(shift))) } - Operand::Immediate(imm) => Some((CmplogOperandType::Imm(imm as u64), None)), + Operand::Immediate(imm) => Some((CmplogOperandType::Imm(u64::from(imm)), None)), _ => panic!("Second argument could not be decoded"), } }; diff --git a/libafl_frida/src/lib.rs b/libafl_frida/src/lib.rs index c9b3eef569..738e0a56d3 100644 --- a/libafl_frida/src/lib.rs +++ b/libafl_frida/src/lib.rs @@ -20,8 +20,7 @@ Additional documentation is available in [the `LibAFL` book](https://aflplus.plu clippy::module_name_repetitions, clippy::unreadable_literal, clippy::ptr_cast_constness, - clippy::must_use_candidate, - clippy::missing_transmute_annotations + clippy::must_use_candidate )] #![cfg_attr(not(test), warn( missing_debug_implementations, diff --git a/libafl_qemu/libafl_qemu_build/src/build.rs b/libafl_qemu/libafl_qemu_build/src/build.rs index 07cf9d8192..cc9ba3b12e 100644 --- a/libafl_qemu/libafl_qemu_build/src/build.rs +++ b/libafl_qemu/libafl_qemu_build/src/build.rs @@ -10,6 +10,7 @@ const QEMU_URL: &str = "https://github.com/AFLplusplus/qemu-libafl-bridge"; const QEMU_DIRNAME: &str = "qemu-libafl-bridge"; const QEMU_REVISION: &str = "821ad471430360c4eed644d07d59f0d603ef23f6"; +#[allow(clippy::module_name_repetitions)] pub struct BuildResult { pub qemu_path: PathBuf, pub build_dir: PathBuf, diff --git a/libafl_qemu/libafl_qemu_sys/src/lib.rs b/libafl_qemu/libafl_qemu_sys/src/lib.rs index a2d63dba4f..f12b706a98 100644 --- a/libafl_qemu/libafl_qemu_sys/src/lib.rs +++ b/libafl_qemu/libafl_qemu_sys/src/lib.rs @@ -14,9 +14,11 @@ __Warning__: The documentation is built by default for `x86_64` in `usermode`. T #![allow(clippy::pedantic)] #[cfg(all(not(feature = "clippy"), target_os = "linux"))] -include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +mod bindings { + include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +} -#[cfg(all(feature = "clippy", target_os = "linux"))] +#[cfg(any(feature = "clippy", not(target_os = "linux")))] mod x86_64_stub_bindings; #[cfg(emulation_mode = "usermode")] @@ -98,7 +100,11 @@ macro_rules! extern_c_checked { use core::ops::BitAnd; use std::{ffi::c_void, slice::from_raw_parts, str::from_utf8_unchecked}; -#[cfg(all(feature = "clippy", target_os = "linux"))] +#[cfg(all(not(feature = "clippy"), target_os = "linux"))] +pub use bindings::*; +#[cfg(feature = "python")] +use pyo3::{pyclass, pymethods, IntoPy, PyObject, Python}; +#[cfg(any(feature = "clippy", not(target_os = "linux")))] pub use x86_64_stub_bindings::*; pub type CPUStatePtr = *mut crate::CPUState; diff --git a/libafl_qemu/src/emu.rs b/libafl_qemu/src/emu.rs index 1356d4f339..3abc72b730 100644 --- a/libafl_qemu/src/emu.rs +++ b/libafl_qemu/src/emu.rs @@ -625,25 +625,25 @@ pub struct HookData(u64); impl From> for HookData { fn from(value: Pin<&mut T>) -> Self { - unsafe { HookData(core::mem::transmute(value)) } + unsafe { HookData(transmute::, u64>(value)) } } } impl From> for HookData { fn from(value: Pin<&T>) -> Self { - unsafe { HookData(core::mem::transmute(value)) } + unsafe { HookData(transmute::, u64>(value)) } } } impl From<&'static mut T> for HookData { fn from(value: &'static mut T) -> Self { - unsafe { HookData(core::mem::transmute(value)) } + unsafe { HookData(transmute::<&mut T, u64>(value)) } } } impl From<&'static T> for HookData { fn from(value: &'static T) -> Self { - unsafe { HookData(core::mem::transmute(value)) } + unsafe { HookData(transmute::<&T, u64>(value)) } } } @@ -903,7 +903,7 @@ impl Qemu { } } } - + #[allow(clippy::missing_transmute_annotations)] fn post_run(&self) -> Result { let exit_reason = unsafe { libafl_get_exit_reason() }; if exit_reason.is_null() { @@ -1068,6 +1068,7 @@ impl Qemu { } // TODO set T lifetime to be like Emulator + #[allow(clippy::missing_transmute_annotations)] pub fn set_hook>( &self, data: T, @@ -1077,7 +1078,7 @@ impl Qemu { ) -> InstructionHookId { unsafe { let data: u64 = data.into().0; - let callback: extern "C" fn(u64, GuestAddr) = core::mem::transmute(callback); + let callback: extern "C" fn(u64, GuestAddr) = transmute(callback); let num = libafl_qemu_sys::libafl_qemu_set_hook( addr.into(), Some(callback), @@ -1100,6 +1101,7 @@ impl Qemu { } } + #[allow(clippy::missing_transmute_annotations)] pub fn add_edge_hooks>( &self, data: T, @@ -1108,14 +1110,14 @@ impl Qemu { ) -> EdgeHookId { unsafe { let data: u64 = data.into().0; - let gen: Option u64> = - core::mem::transmute(gen); - let exec: Option = core::mem::transmute(exec); + let gen: Option u64> = transmute(gen); + let exec: Option = transmute(exec); let num = libafl_qemu_sys::libafl_add_edge_hook(gen, exec, data); EdgeHookId(num) } } + #[allow(clippy::missing_transmute_annotations)] pub fn add_block_hooks>( &self, data: T, @@ -1125,15 +1127,15 @@ impl Qemu { ) -> BlockHookId { unsafe { let data: u64 = data.into().0; - let gen: Option u64> = core::mem::transmute(gen); - let post_gen: Option = - core::mem::transmute(post_gen); - let exec: Option = core::mem::transmute(exec); + let gen: Option u64> = transmute(gen); + let post_gen: Option = transmute(post_gen); + let exec: Option = transmute(exec); let num = libafl_qemu_sys::libafl_add_block_hook(gen, post_gen, exec, data); BlockHookId(num) } } + #[allow(clippy::missing_transmute_annotations)] pub fn add_read_hooks>( &self, data: T, @@ -1147,13 +1149,12 @@ impl Qemu { unsafe { let data: u64 = data.into().0; let gen: Option u64> = - core::mem::transmute(gen); - let exec1: Option = core::mem::transmute(exec1); - let exec2: Option = core::mem::transmute(exec2); - let exec4: Option = core::mem::transmute(exec4); - let exec8: Option = core::mem::transmute(exec8); - let exec_n: Option = - core::mem::transmute(exec_n); + transmute(gen); + let exec1: Option = transmute(exec1); + let exec2: Option = transmute(exec2); + let exec4: Option = transmute(exec4); + let exec8: Option = transmute(exec8); + let exec_n: Option = transmute(exec_n); let num = libafl_qemu_sys::libafl_add_read_hook( gen, exec1, exec2, exec4, exec8, exec_n, data, ); @@ -1162,6 +1163,7 @@ impl Qemu { } // TODO add MemOp info + #[allow(clippy::missing_transmute_annotations)] pub fn add_write_hooks>( &self, data: T, @@ -1175,13 +1177,12 @@ impl Qemu { unsafe { let data: u64 = data.into().0; let gen: Option u64> = - core::mem::transmute(gen); - let exec1: Option = core::mem::transmute(exec1); - let exec2: Option = core::mem::transmute(exec2); - let exec4: Option = core::mem::transmute(exec4); - let exec8: Option = core::mem::transmute(exec8); - let exec_n: Option = - core::mem::transmute(exec_n); + transmute(gen); + let exec1: Option = transmute(exec1); + let exec2: Option = transmute(exec2); + let exec4: Option = transmute(exec4); + let exec8: Option = transmute(exec8); + let exec_n: Option = transmute(exec_n); let num = libafl_qemu_sys::libafl_add_write_hook( gen, exec1, exec2, exec4, exec8, exec_n, data, ); @@ -1189,6 +1190,7 @@ impl Qemu { } } + #[allow(clippy::missing_transmute_annotations)] pub fn add_cmp_hooks>( &self, data: T, @@ -1200,17 +1202,17 @@ impl Qemu { ) -> CmpHookId { unsafe { let data: u64 = data.into().0; - let gen: Option u64> = - core::mem::transmute(gen); - let exec1: Option = core::mem::transmute(exec1); - let exec2: Option = core::mem::transmute(exec2); - let exec4: Option = core::mem::transmute(exec4); - let exec8: Option = core::mem::transmute(exec8); + let gen: Option u64> = transmute(gen); + let exec1: Option = transmute(exec1); + let exec2: Option = transmute(exec2); + let exec4: Option = transmute(exec4); + let exec8: Option = transmute(exec8); let num = libafl_qemu_sys::libafl_add_cmp_hook(gen, exec1, exec2, exec4, exec8, data); CmpHookId(num) } } + #[allow(clippy::missing_transmute_annotations)] pub fn add_backdoor_hook>( &self, data: T, @@ -1218,7 +1220,7 @@ impl Qemu { ) -> BackdoorHookId { unsafe { let data: u64 = data.into().0; - let callback: extern "C" fn(u64, GuestAddr) = core::mem::transmute(callback); + let callback: extern "C" fn(u64, GuestAddr) = transmute(callback); let num = libafl_qemu_sys::libafl_add_backdoor_hook(Some(callback), data); BackdoorHookId(num) } @@ -1227,7 +1229,10 @@ impl Qemu { #[allow(clippy::type_complexity)] pub fn add_gdb_cmd(&self, callback: Box bool>) { unsafe { - let fat: Box = Box::new(transmute(callback)); + let fat: Box = Box::new(transmute::< + Box FnMut(&'a Qemu, &'b str) -> bool>, + FatPtr, + >(callback)); libafl_qemu_add_gdb_cmd(gdb_cmd, core::ptr::from_ref(&*fat) as *const ()); GDB_COMMANDS.push(fat); } diff --git a/libafl_qemu/src/hooks.rs b/libafl_qemu/src/hooks.rs index 9ed5f03d9f..d2961fc5a5 100644 --- a/libafl_qemu/src/hooks.rs +++ b/libafl_qemu/src/hooks.rs @@ -1,5 +1,5 @@ //! The high-level hooks -#![allow(clippy::type_complexity)] +#![allow(clippy::type_complexity, clippy::missing_transmute_annotations)] #[cfg(emulation_mode = "usermode")] use core::ptr::addr_of_mut; diff --git a/libafl_qemu/src/lib.rs b/libafl_qemu/src/lib.rs index ac4927bd0a..b42b35a954 100644 --- a/libafl_qemu/src/lib.rs +++ b/libafl_qemu/src/lib.rs @@ -18,7 +18,6 @@ #![allow(clippy::transmute_ptr_to_ptr)] #![allow(clippy::ptr_cast_constness)] #![allow(clippy::too_many_arguments)] -#![allow(clippy::missing_transmute_annotations)] // Till they fix this buggy lint in clippy #![allow(clippy::borrow_as_ptr)] #![allow(clippy::borrow_deref_ref)] diff --git a/libafl_targets/src/lib.rs b/libafl_targets/src/lib.rs index 3cf7253649..b2fe9e294a 100644 --- a/libafl_targets/src/lib.rs +++ b/libafl_targets/src/lib.rs @@ -14,8 +14,7 @@ clippy::missing_panics_doc, clippy::missing_docs_in_private_items, clippy::module_name_repetitions, - clippy::pub_underscore_fields, - clippy::missing_transmute_annotations + clippy::pub_underscore_fields )] #![cfg_attr(not(test), warn( missing_debug_implementations, diff --git a/scripts/autofix.sh b/scripts/autofix.sh index 705b210fff..b253c90d2d 100755 --- a/scripts/autofix.sh +++ b/scripts/autofix.sh @@ -11,13 +11,13 @@ fi echo echo "[+] Fixing build" -cargo +nightly fix --release --workspace --all-features +cargo +nightly fix --release --workspace --all-features --allow-dirty --allow-staged echo "[+] Done fixing build" echo echo 'Fixing clippy (might need a "git commit" and a rerun, if "cargo fix" changed the source)' -RUST_BACKTRACE=full cargo +nightly clippy --fix --release --all --all-features --tests --examples --benches -- -Z macro-backtrace \ +RUST_BACKTRACE=full cargo +nightly clippy --fix --release --all --all-features --tests --examples --benches --allow-dirty --allow-staged -- -Z macro-backtrace \ -D clippy::all \ -D clippy::pedantic \ -W clippy::similar_names \