From 973c4358e6c99e61964867ddd0247b71b8061603 Mon Sep 17 00:00:00 2001 From: "Dongjia \"toka\" Zhang" Date: Tue, 13 Feb 2024 13:19:00 +0100 Subject: [PATCH] clippy (#1851) --- libafl/src/corpus/mod.rs | 8 +++++--- libafl/src/executors/differential.rs | 4 ++-- libafl/src/executors/hooks/timer.rs | 2 +- libafl/src/executors/inprocess.rs | 13 +++++++------ libafl/src/executors/inprocess_fork.rs | 6 +++--- libafl/src/executors/mod.rs | 4 ++-- libafl/src/feedbacks/mod.rs | 6 +++--- libafl/src/monitors/mod.rs | 4 ++-- libafl/src/observers/mod.rs | 6 +++--- libafl_frida/src/asan/asan_rt.rs | 2 +- libafl_qemu/src/emu.rs | 2 +- libafl_qemu/src/executor.rs | 2 +- libafl_targets/src/cmps/mod.rs | 2 +- 13 files changed, 32 insertions(+), 29 deletions(-) diff --git a/libafl/src/corpus/mod.rs b/libafl/src/corpus/mod.rs index 47f01d22e4..0cfcc39c27 100644 --- a/libafl/src/corpus/mod.rs +++ b/libafl/src/corpus/mod.rs @@ -361,21 +361,23 @@ pub mod pybind { fn get(&self, idx: CorpusId) -> Result<&RefCell>, Error> { let ptr = unwrap_me!(self.wrapper, c, { c.get(idx) - .map(|v| v as *const RefCell>) + .map(core::ptr::from_ref::>>) })?; Ok(unsafe { ptr.as_ref().unwrap() }) } #[inline] fn current(&self) -> &Option { - let ptr = unwrap_me!(self.wrapper, c, { c.current() as *const Option }); + let ptr = unwrap_me!(self.wrapper, c, { + core::ptr::from_ref::>(c.current()) + }); unsafe { ptr.as_ref().unwrap() } } #[inline] fn current_mut(&mut self) -> &mut Option { let ptr = unwrap_me_mut!(self.wrapper, c, { - c.current_mut() as *mut Option + core::ptr::from_mut::>(c.current_mut()) }); unsafe { ptr.as_mut().unwrap() } } diff --git a/libafl/src/executors/differential.rs b/libafl/src/executors/differential.rs index 8da268f4cb..745c4ed1b7 100644 --- a/libafl/src/executors/differential.rs +++ b/libafl/src/executors/differential.rs @@ -205,8 +205,8 @@ where impl ProxyObserversTuple { fn set(&mut self, primary: &A, secondary: &B) { - self.primary = OwnedMutPtr::Ptr(primary as *const A as *mut A); - self.secondary = OwnedMutPtr::Ptr(secondary as *const B as *mut B); + self.primary = OwnedMutPtr::Ptr(core::ptr::from_ref::(primary) as *mut A); + self.secondary = OwnedMutPtr::Ptr(core::ptr::from_ref::(secondary) as *mut B); } } diff --git a/libafl/src/executors/hooks/timer.rs b/libafl/src/executors/hooks/timer.rs index e402656bee..2f93f2192e 100644 --- a/libafl/src/executors/hooks/timer.rs +++ b/libafl/src/executors/hooks/timer.rs @@ -299,7 +299,7 @@ impl TimerStruct { let data = addr_of_mut!(GLOBAL_STATE); write_volatile( addr_of_mut!((*data).executor_ptr), - self as *mut _ as *mut c_void, + core::ptr::from_mut(self) as *mut c_void, ); if self.executions == 0 { diff --git a/libafl/src/executors/inprocess.rs b/libafl/src/executors/inprocess.rs index b28e6677dc..f405118507 100644 --- a/libafl/src/executors/inprocess.rs +++ b/libafl/src/executors/inprocess.rs @@ -178,25 +178,25 @@ where let data = addr_of_mut!(GLOBAL_STATE); write_volatile( addr_of_mut!((*data).current_input_ptr), - input as *const _ as *const c_void, + core::ptr::from_ref(input) as *const c_void, ); write_volatile( addr_of_mut!((*data).executor_ptr), - self as *const _ as *const c_void, + core::ptr::from_ref(self) as *const c_void, ); // Direct raw pointers access /aliasing is pretty undefined behavior. // Since the state and event may have moved in memory, refresh them right before the signal may happen write_volatile( addr_of_mut!((*data).state_ptr), - state as *mut _ as *mut c_void, + core::ptr::from_mut(state) as *mut c_void, ); write_volatile( addr_of_mut!((*data).event_mgr_ptr), - mgr as *mut _ as *mut c_void, + core::ptr::from_mut(mgr) as *mut c_void, ); write_volatile( addr_of_mut!((*data).fuzzer_ptr), - fuzzer as *mut _ as *mut c_void, + core::ptr::from_mut(fuzzer) as *mut c_void, ); compiler_fence(Ordering::SeqCst); } @@ -252,7 +252,8 @@ where ) } - /// Create a new in mem executor with the default timeout and use batch mode(5 sec) + /// Create a new in mem executor with the default timeout and use batch mode (5 sec) + /// Do not use batched mode timeouts with cmplog cores. It is not supported #[cfg(all(feature = "std", target_os = "linux"))] pub fn batched_timeouts( harness_fn: &'a mut H, diff --git a/libafl/src/executors/inprocess_fork.rs b/libafl/src/executors/inprocess_fork.rs index 289392c6a1..51e03ee862 100644 --- a/libafl/src/executors/inprocess_fork.rs +++ b/libafl/src/executors/inprocess_fork.rs @@ -278,15 +278,15 @@ where let data = addr_of_mut!(FORK_EXECUTOR_GLOBAL_DATA); write_volatile( addr_of_mut!((*data).executor_ptr), - self as *const _ as *const c_void, + core::ptr::from_ref(self) as *const c_void, ); write_volatile( addr_of_mut!((*data).current_input_ptr), - input as *const _ as *const c_void, + core::ptr::from_ref(input) as *const c_void, ); write_volatile( addr_of_mut!((*data).state_ptr), - state as *mut _ as *mut c_void, + core::ptr::from_mut(state) as *mut c_void, ); compiler_fence(Ordering::SeqCst); } diff --git a/libafl/src/executors/mod.rs b/libafl/src/executors/mod.rs index 91b4140ab3..9fed40d22f 100644 --- a/libafl/src/executors/mod.rs +++ b/libafl/src/executors/mod.rs @@ -498,7 +498,7 @@ pub mod pybind { #[inline] fn observers(&self) -> &PythonObserversTuple { let ptr = unwrap_me!(self.wrapper, e, { - e.observers() as *const PythonObserversTuple + core::ptr::from_ref::(e.observers()) }); unsafe { ptr.as_ref().unwrap() } } @@ -506,7 +506,7 @@ pub mod pybind { #[inline] fn observers_mut(&mut self) -> &mut PythonObserversTuple { let ptr = unwrap_me_mut!(self.wrapper, e, { - e.observers_mut() as *mut PythonObserversTuple + core::ptr::from_mut::(e.observers_mut()) }); unsafe { ptr.as_mut().unwrap() } } diff --git a/libafl/src/feedbacks/mod.rs b/libafl/src/feedbacks/mod.rs index eaa094aa5a..af57449d6d 100644 --- a/libafl/src/feedbacks/mod.rs +++ b/libafl/src/feedbacks/mod.rs @@ -1187,9 +1187,9 @@ pub mod pybind { // # Safety // We use this observer in Python ony when the ObserverTuple is PythonObserversTuple let dont_look_at_this: &PythonObserversTuple = - unsafe { &*(observers as *const OT as *const PythonObserversTuple) }; + unsafe { &*(core::ptr::from_ref::(observers) as *const PythonObserversTuple) }; let dont_look_at_this2: &PythonEventManager = - unsafe { &*(manager as *mut EM as *const PythonEventManager) }; + unsafe { &*(core::ptr::from_mut::(manager) as *const PythonEventManager) }; Ok(Python::with_gil(|py| -> PyResult { let r: bool = self .inner @@ -1221,7 +1221,7 @@ pub mod pybind { // # Safety // We use this observer in Python ony when the ObserverTuple is PythonObserversTuple let dont_look_at_this: &PythonObserversTuple = - unsafe { &*(observers as *const OT as *const PythonObserversTuple) }; + unsafe { &*(core::ptr::from_ref::(observers) as *const PythonObserversTuple) }; Python::with_gil(|py| -> PyResult<()> { self.inner.call_method1( py, diff --git a/libafl/src/monitors/mod.rs b/libafl/src/monitors/mod.rs index f2bbe0e937..e86ca7f8b8 100644 --- a/libafl/src/monitors/mod.rs +++ b/libafl/src/monitors/mod.rs @@ -1407,14 +1407,14 @@ pub mod pybind { impl Monitor for PythonMonitor { fn client_stats_mut(&mut self) -> &mut Vec { let ptr = unwrap_me_mut!(self.wrapper, m, { - m.client_stats_mut() as *mut Vec + core::ptr::from_mut::>(m.client_stats_mut()) }); unsafe { ptr.as_mut().unwrap() } } fn client_stats(&self) -> &[ClientStats] { let ptr = unwrap_me!(self.wrapper, m, { - m.client_stats() as *const [ClientStats] + core::ptr::from_ref::<[ClientStats]>(m.client_stats()) }); unsafe { ptr.as_ref().unwrap() } } diff --git a/libafl/src/observers/mod.rs b/libafl/src/observers/mod.rs index 46c0e0e46f..ec4a0e3974 100644 --- a/libafl/src/observers/mod.rs +++ b/libafl/src/observers/mod.rs @@ -1047,7 +1047,7 @@ pub mod pybind { impl Named for PythonObserver { fn name(&self) -> &str { - let ptr = unwrap_me!(self.wrapper, o, { o.name() as *const str }); + let ptr = unwrap_me!(self.wrapper, o, { core::ptr::from_ref::(o.name()) }); unsafe { ptr.as_ref().unwrap() } } } @@ -1266,7 +1266,7 @@ pub mod pybind { } PythonObserverWrapper::Python(py_wrapper) => { if type_eq::() && py_wrapper.name() == name { - r = (py_wrapper as *const _ as *const T).as_ref(); + r = (core::ptr::from_ref(py_wrapper) as *const T).as_ref(); } } } @@ -1359,7 +1359,7 @@ pub mod pybind { } PythonObserverWrapper::Python(py_wrapper) => { if type_eq::() && py_wrapper.name() == name { - r = (py_wrapper as *mut _ as *mut T).as_mut(); + r = (core::ptr::from_mut(py_wrapper) as *mut T).as_mut(); } } } diff --git a/libafl_frida/src/asan/asan_rt.rs b/libafl_frida/src/asan/asan_rt.rs index b245ba8e65..4d0328e815 100644 --- a/libafl_frida/src/asan/asan_rt.rs +++ b/libafl_frida/src/asan/asan_rt.rs @@ -1942,7 +1942,7 @@ impl AsanRuntime { ;->accessed_address: ; .dword 0x0 ; self_addr: - ; .qword self as *mut _ as *mut c_void as i64 + ; .qword core::ptr::from_mut(self) as *mut c_void as i64 ; self_regs_addr: ; .qword addr_of_mut!(self.regs) as i64 ; trap_func: diff --git a/libafl_qemu/src/emu.rs b/libafl_qemu/src/emu.rs index b0c3cc5e44..e870dbeeca 100644 --- a/libafl_qemu/src/emu.rs +++ b/libafl_qemu/src/emu.rs @@ -1700,7 +1700,7 @@ impl Emulator { pub fn add_gdb_cmd(&self, callback: Box bool>) { unsafe { let fat: Box = Box::new(transmute(callback)); - libafl_qemu_add_gdb_cmd(gdb_cmd, &*fat as *const _ as *const ()); + libafl_qemu_add_gdb_cmd(gdb_cmd, core::ptr::from_ref(&*fat) as *const ()); GDB_COMMANDS.push(fat); } } diff --git a/libafl_qemu/src/executor.rs b/libafl_qemu/src/executor.rs index 2e4be7b7f9..f1eff488b6 100644 --- a/libafl_qemu/src/executor.rs +++ b/libafl_qemu/src/executor.rs @@ -79,7 +79,7 @@ pub unsafe fn inproc_qemu_crash_handler( Z: HasObjective, { let puc = match &mut context { - Some(v) => (*v) as *mut ucontext_t as *mut c_void, + Some(v) => core::ptr::from_mut::(*v) as *mut c_void, None => core::ptr::null_mut(), }; libafl_qemu_handle_crash(signal as i32, info, puc); diff --git a/libafl_targets/src/cmps/mod.rs b/libafl_targets/src/cmps/mod.rs index b59171b5df..095103484d 100644 --- a/libafl_targets/src/cmps/mod.rs +++ b/libafl_targets/src/cmps/mod.rs @@ -481,7 +481,7 @@ impl Serialize for AFLppCmpLogMap { { let slice = unsafe { core::slice::from_raw_parts( - (self as *const Self) as *const u8, + (core::ptr::from_ref::(self)) as *const u8, core::mem::size_of::(), ) };