Cleanup Pointer Clippy Lints (#1861)

* Fix pointer clippy lints

* More clippy

* fix build

* fix
This commit is contained in:
Dominik Maier 2024-02-15 16:31:18 +01:00 committed by GitHub
parent b999b4aac5
commit 0a995f241c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 47 additions and 56 deletions

View File

@ -368,17 +368,13 @@ pub mod pybind {
#[inline] #[inline]
fn current(&self) -> &Option<CorpusId> { fn current(&self) -> &Option<CorpusId> {
let ptr = unwrap_me!(self.wrapper, c, { let ptr = unwrap_me!(self.wrapper, c, { core::ptr::from_ref(c.current()) });
core::ptr::from_ref::<Option<CorpusId>>(c.current())
});
unsafe { ptr.as_ref().unwrap() } unsafe { ptr.as_ref().unwrap() }
} }
#[inline] #[inline]
fn current_mut(&mut self) -> &mut Option<CorpusId> { fn current_mut(&mut self) -> &mut Option<CorpusId> {
let ptr = unwrap_me_mut!(self.wrapper, c, { let ptr = unwrap_me_mut!(self.wrapper, c, { core::ptr::from_mut(c.current_mut()) });
core::ptr::from_mut::<Option<CorpusId>>(c.current_mut())
});
unsafe { ptr.as_mut().unwrap() } unsafe { ptr.as_mut().unwrap() }
} }

View File

@ -2,7 +2,7 @@
//! It wraps two executors that will be run after each other with the same input. //! It wraps two executors that will be run after each other with the same input.
//! In comparison to the [`crate::executors::CombinedExecutor`] it also runs the secondary executor in `run_target`. //! In comparison to the [`crate::executors::CombinedExecutor`] it also runs the secondary executor in `run_target`.
//! //!
use core::{cell::UnsafeCell, fmt::Debug}; use core::{cell::UnsafeCell, fmt::Debug, ptr};
use libafl_bolts::{ownedref::OwnedMutPtr, tuples::MatchName}; use libafl_bolts::{ownedref::OwnedMutPtr, tuples::MatchName};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -205,8 +205,8 @@ where
impl<A, B, DOT> ProxyObserversTuple<A, B, DOT> { impl<A, B, DOT> ProxyObserversTuple<A, B, DOT> {
fn set(&mut self, primary: &A, secondary: &B) { fn set(&mut self, primary: &A, secondary: &B) {
self.primary = OwnedMutPtr::Ptr(core::ptr::from_ref::<A>(primary) as *mut A); self.primary = OwnedMutPtr::Ptr(ptr::from_ref(primary) as *mut A);
self.secondary = OwnedMutPtr::Ptr(core::ptr::from_ref::<B>(secondary) as *mut B); self.secondary = OwnedMutPtr::Ptr(ptr::from_ref(secondary) as *mut B);
} }
} }

View File

@ -8,7 +8,7 @@ use core::{
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
use core::{ use core::{
mem::zeroed, mem::zeroed,
ptr::{addr_of, null_mut}, ptr::{self, addr_of, null_mut},
}; };
#[cfg(all(unix, not(target_os = "linux")))] #[cfg(all(unix, not(target_os = "linux")))]
@ -299,7 +299,7 @@ impl TimerStruct {
let data = addr_of_mut!(GLOBAL_STATE); let data = addr_of_mut!(GLOBAL_STATE);
write_volatile( write_volatile(
addr_of_mut!((*data).executor_ptr), addr_of_mut!((*data).executor_ptr),
core::ptr::from_mut(self) as *mut c_void, ptr::from_mut(self) as *mut c_void,
); );
if self.executions == 0 { if self.executions == 0 {

View File

@ -185,8 +185,8 @@ pub mod unix_signal_handler {
{ {
#[cfg(all(target_os = "android", target_arch = "aarch64"))] #[cfg(all(target_os = "android", target_arch = "aarch64"))]
let _context = _context.map(|p| { let _context = _context.map(|p| {
&mut *(((p as *mut _ as *mut libc::c_void as usize) + 128) as *mut libc::c_void &mut *(((core::ptr::from_mut(p) as *mut libc::c_void as usize) + 128)
as *mut ucontext_t) as *mut libc::c_void as *mut ucontext_t)
}); });
log::error!("Crashed with {signal}"); log::error!("Crashed with {signal}");

View File

@ -10,7 +10,7 @@ use core::{
ffi::c_void, ffi::c_void,
fmt::{self, Debug, Formatter}, fmt::{self, Debug, Formatter},
marker::PhantomData, marker::PhantomData,
ptr::{addr_of_mut, null, write_volatile}, ptr::{self, addr_of_mut, null, write_volatile},
sync::atomic::{compiler_fence, Ordering}, sync::atomic::{compiler_fence, Ordering},
time::Duration, time::Duration,
}; };
@ -178,25 +178,25 @@ where
let data = addr_of_mut!(GLOBAL_STATE); let data = addr_of_mut!(GLOBAL_STATE);
write_volatile( write_volatile(
addr_of_mut!((*data).current_input_ptr), addr_of_mut!((*data).current_input_ptr),
core::ptr::from_ref(input) as *const c_void, ptr::from_ref(input) as *const c_void,
); );
write_volatile( write_volatile(
addr_of_mut!((*data).executor_ptr), addr_of_mut!((*data).executor_ptr),
core::ptr::from_ref(self) as *const c_void, ptr::from_ref(self) as *const c_void,
); );
// Direct raw pointers access /aliasing is pretty undefined behavior. // 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 // Since the state and event may have moved in memory, refresh them right before the signal may happen
write_volatile( write_volatile(
addr_of_mut!((*data).state_ptr), addr_of_mut!((*data).state_ptr),
core::ptr::from_mut(state) as *mut c_void, ptr::from_mut(state) as *mut c_void,
); );
write_volatile( write_volatile(
addr_of_mut!((*data).event_mgr_ptr), addr_of_mut!((*data).event_mgr_ptr),
core::ptr::from_mut(mgr) as *mut c_void, ptr::from_mut(mgr) as *mut c_void,
); );
write_volatile( write_volatile(
addr_of_mut!((*data).fuzzer_ptr), addr_of_mut!((*data).fuzzer_ptr),
core::ptr::from_mut(fuzzer) as *mut c_void, ptr::from_mut(fuzzer) as *mut c_void,
); );
compiler_fence(Ordering::SeqCst); compiler_fence(Ordering::SeqCst);
} }

View File

@ -3,7 +3,7 @@ use core::{
ffi::c_void, ffi::c_void,
fmt::{self, Debug, Formatter}, fmt::{self, Debug, Formatter},
marker::PhantomData, marker::PhantomData,
ptr::{addr_of_mut, null_mut, write_volatile}, ptr::{self, addr_of_mut, null_mut, write_volatile},
sync::atomic::{compiler_fence, Ordering}, sync::atomic::{compiler_fence, Ordering},
time::Duration, time::Duration,
}; };
@ -278,15 +278,15 @@ where
let data = addr_of_mut!(FORK_EXECUTOR_GLOBAL_DATA); let data = addr_of_mut!(FORK_EXECUTOR_GLOBAL_DATA);
write_volatile( write_volatile(
addr_of_mut!((*data).executor_ptr), addr_of_mut!((*data).executor_ptr),
core::ptr::from_ref(self) as *const c_void, ptr::from_ref(self) as *const c_void,
); );
write_volatile( write_volatile(
addr_of_mut!((*data).current_input_ptr), addr_of_mut!((*data).current_input_ptr),
core::ptr::from_ref(input) as *const c_void, ptr::from_ref(input) as *const c_void,
); );
write_volatile( write_volatile(
addr_of_mut!((*data).state_ptr), addr_of_mut!((*data).state_ptr),
core::ptr::from_mut(state) as *mut c_void, ptr::from_mut(state) as *mut c_void,
); );
compiler_fence(Ordering::SeqCst); compiler_fence(Ordering::SeqCst);
} }

View File

@ -497,17 +497,13 @@ pub mod pybind {
impl HasObservers for PythonExecutor { impl HasObservers for PythonExecutor {
#[inline] #[inline]
fn observers(&self) -> &PythonObserversTuple { fn observers(&self) -> &PythonObserversTuple {
let ptr = unwrap_me!(self.wrapper, e, { let ptr = unwrap_me!(self.wrapper, e, { core::ptr::from_ref(e.observers()) });
core::ptr::from_ref::<PythonObserversTuple>(e.observers())
});
unsafe { ptr.as_ref().unwrap() } unsafe { ptr.as_ref().unwrap() }
} }
#[inline] #[inline]
fn observers_mut(&mut self) -> &mut PythonObserversTuple { fn observers_mut(&mut self) -> &mut PythonObserversTuple {
let ptr = unwrap_me_mut!(self.wrapper, e, { let ptr = unwrap_me_mut!(self.wrapper, e, { core::ptr::from_mut(e.observers_mut()) });
core::ptr::from_mut::<PythonObserversTuple>(e.observers_mut())
});
unsafe { ptr.as_mut().unwrap() } unsafe { ptr.as_mut().unwrap() }
} }
} }

View File

@ -1097,6 +1097,7 @@ impl From<bool> for ConstFeedback {
#[allow(clippy::unnecessary_fallible_conversions)] #[allow(clippy::unnecessary_fallible_conversions)]
#[allow(missing_docs)] #[allow(missing_docs)]
pub mod pybind { pub mod pybind {
use core::ptr;
use std::cell::UnsafeCell; use std::cell::UnsafeCell;
use libafl_bolts::Named; use libafl_bolts::Named;
@ -1187,9 +1188,9 @@ pub mod pybind {
// # Safety // # Safety
// We use this observer in Python ony when the ObserverTuple is PythonObserversTuple // We use this observer in Python ony when the ObserverTuple is PythonObserversTuple
let dont_look_at_this: &PythonObserversTuple = let dont_look_at_this: &PythonObserversTuple =
unsafe { &*(core::ptr::from_ref::<OT>(observers) as *const PythonObserversTuple) }; unsafe { &*(ptr::from_ref(observers) as *const PythonObserversTuple) };
let dont_look_at_this2: &PythonEventManager = let dont_look_at_this2: &PythonEventManager =
unsafe { &*(core::ptr::from_mut::<EM>(manager) as *const PythonEventManager) }; unsafe { &*(ptr::from_mut(manager) as *const PythonEventManager) };
Ok(Python::with_gil(|py| -> PyResult<bool> { Ok(Python::with_gil(|py| -> PyResult<bool> {
let r: bool = self let r: bool = self
.inner .inner
@ -1221,7 +1222,7 @@ pub mod pybind {
// # Safety // # Safety
// We use this observer in Python ony when the ObserverTuple is PythonObserversTuple // We use this observer in Python ony when the ObserverTuple is PythonObserversTuple
let dont_look_at_this: &PythonObserversTuple = let dont_look_at_this: &PythonObserversTuple =
unsafe { &*(core::ptr::from_ref::<OT>(observers) as *const PythonObserversTuple) }; unsafe { &*(ptr::from_ref(observers) as *const PythonObserversTuple) };
Python::with_gil(|py| -> PyResult<()> { Python::with_gil(|py| -> PyResult<()> {
self.inner.call_method1( self.inner.call_method1(
py, py,

View File

@ -1407,15 +1407,13 @@ pub mod pybind {
impl Monitor for PythonMonitor { impl Monitor for PythonMonitor {
fn client_stats_mut(&mut self) -> &mut Vec<ClientStats> { fn client_stats_mut(&mut self) -> &mut Vec<ClientStats> {
let ptr = unwrap_me_mut!(self.wrapper, m, { let ptr = unwrap_me_mut!(self.wrapper, m, {
core::ptr::from_mut::<Vec<ClientStats>>(m.client_stats_mut()) core::ptr::from_mut(m.client_stats_mut())
}); });
unsafe { ptr.as_mut().unwrap() } unsafe { ptr.as_mut().unwrap() }
} }
fn client_stats(&self) -> &[ClientStats] { fn client_stats(&self) -> &[ClientStats] {
let ptr = unwrap_me!(self.wrapper, m, { let ptr = unwrap_me!(self.wrapper, m, { core::ptr::from_ref(m.client_stats()) });
core::ptr::from_ref::<[ClientStats]>(m.client_stats())
});
unsafe { ptr.as_ref().unwrap() } unsafe { ptr.as_ref().unwrap() }
} }

View File

@ -593,6 +593,7 @@ where
#[cfg(feature = "python")] #[cfg(feature = "python")]
#[allow(missing_docs)] #[allow(missing_docs)]
pub mod pybind { pub mod pybind {
use core::ptr;
use std::cell::UnsafeCell; use std::cell::UnsafeCell;
use libafl_bolts::{ use libafl_bolts::{
@ -1047,7 +1048,7 @@ pub mod pybind {
impl Named for PythonObserver { impl Named for PythonObserver {
fn name(&self) -> &str { fn name(&self) -> &str {
let ptr = unwrap_me!(self.wrapper, o, { core::ptr::from_ref::<str>(o.name()) }); let ptr = unwrap_me!(self.wrapper, o, { ptr::from_ref::<str>(o.name()) });
unsafe { ptr.as_ref().unwrap() } unsafe { ptr.as_ref().unwrap() }
} }
} }
@ -1266,7 +1267,7 @@ pub mod pybind {
} }
PythonObserverWrapper::Python(py_wrapper) => { PythonObserverWrapper::Python(py_wrapper) => {
if type_eq::<PyObjectObserver, T>() && py_wrapper.name() == name { if type_eq::<PyObjectObserver, T>() && py_wrapper.name() == name {
r = (core::ptr::from_ref(py_wrapper) as *const T).as_ref(); r = (ptr::from_ref(py_wrapper) as *const T).as_ref();
} }
} }
} }
@ -1352,14 +1353,13 @@ pub mod pybind {
if type_eq::<PythonMapObserverU64, T>() if type_eq::<PythonMapObserverU64, T>()
&& py_wrapper.borrow(py).name() == name && py_wrapper.borrow(py).name() == name
{ {
r = (std::ptr::addr_of!(*(*py_wrapper).borrow_mut(py)) r = (ptr::addr_of!(*(*py_wrapper).borrow_mut(py)) as *mut T)
as *mut T)
.as_mut(); .as_mut();
} }
} }
PythonObserverWrapper::Python(py_wrapper) => { PythonObserverWrapper::Python(py_wrapper) => {
if type_eq::<PyObjectObserver, T>() && py_wrapper.name() == name { if type_eq::<PyObjectObserver, T>() && py_wrapper.name() == name {
r = (core::ptr::from_mut(py_wrapper) as *mut T).as_mut(); r = (ptr::from_mut(py_wrapper) as *mut T).as_mut();
} }
} }
} }

View File

@ -565,7 +565,7 @@ impl AsanRuntime {
interceptor.replace( interceptor.replace(
frida_gum::Module::find_export_by_name($lib, stringify!($name)).expect("Failed to find function"), frida_gum::Module::find_export_by_name($lib, stringify!($name)).expect("Failed to find function"),
NativePointer([<replacement_ $name>] as *mut c_void), NativePointer([<replacement_ $name>] as *mut c_void),
NativePointer(self as *mut _ as *mut c_void) NativePointer(core::ptr::from_mut(self) as *mut c_void)
).ok(); ).ok();
} }
} }
@ -590,7 +590,7 @@ impl AsanRuntime {
interceptor.replace( interceptor.replace(
frida_gum::Module::find_export_by_name($lib, stringify!($name)).expect("Failed to find function"), frida_gum::Module::find_export_by_name($lib, stringify!($name)).expect("Failed to find function"),
NativePointer([<replacement_ $name>] as *mut c_void), NativePointer([<replacement_ $name>] as *mut c_void),
NativePointer(self as *mut _ as *mut c_void) NativePointer(core::ptr::from_mut(self) as *mut c_void)
).ok(); ).ok();
} }
} }
@ -1942,7 +1942,7 @@ impl AsanRuntime {
;->accessed_address: ;->accessed_address:
; .dword 0x0 ; .dword 0x0
; self_addr: ; self_addr:
; .qword core::ptr::from_mut(self) as *mut c_void as i64 ; .qword core::ptr::from_mut(self) as *mut c_void as i64
; self_regs_addr: ; self_regs_addr:
; .qword addr_of_mut!(self.regs) as i64 ; .qword addr_of_mut!(self.regs) as i64
; trap_func: ; trap_func:
@ -2041,7 +2041,7 @@ impl AsanRuntime {
; br x1 // go back to the 'return address' ; br x1 // go back to the 'return address'
; self_addr: ; 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: ; self_regs_addr:
; .qword addr_of_mut!(self.regs) as i64 ; .qword addr_of_mut!(self.regs) as i64
; trap_func: ; trap_func:

View File

@ -247,7 +247,7 @@ impl CmpLogRuntime {
; ldp x2, x3, [sp], #0x10 ; ldp x2, x3, [sp], #0x10
; b >done ; b >done
; self_addr: ; self_addr:
; .qword self as *mut _ as *mut c_void as i64 ; .qword core::ptr::from_mut(self) as *mut c_void as i64
; populate_lists: ; populate_lists:
; .qword CmpLogRuntime::populate_lists as *mut c_void as i64 ; .qword CmpLogRuntime::populate_lists as *mut c_void as i64
; done: ; done:

View File

@ -90,11 +90,11 @@ impl<T> __IncompleteArrayField<T> {
} }
#[inline] #[inline]
pub fn as_ptr(&self) -> *const T { pub fn as_ptr(&self) -> *const T {
self as *const _ as *const T core::ptr::from_ref(self) as *const T
} }
#[inline] #[inline]
pub fn as_mut_ptr(&mut self) -> *mut T { pub fn as_mut_ptr(&mut self) -> *mut T {
self as *mut _ as *mut T core::ptr::from_mut(self) as *mut T
} }
#[inline] #[inline]
pub unsafe fn as_slice(&self, len: usize) -> &[T] { pub unsafe fn as_slice(&self, len: usize) -> &[T] {

View File

@ -1,4 +1,6 @@
//! A `QEMU`-based executor for binary-only instrumentation in `LibAFL` //! A `QEMU`-based executor for binary-only instrumentation in `LibAFL`
#[cfg(emulation_mode = "usermode")]
use core::ptr;
use core::{ use core::{
ffi::c_void, ffi::c_void,
fmt::{self, Debug, Formatter}, fmt::{self, Debug, Formatter},
@ -79,8 +81,8 @@ pub unsafe fn inproc_qemu_crash_handler<E, EM, OF, Z>(
Z: HasObjective<Objective = OF, State = E::State>, Z: HasObjective<Objective = OF, State = E::State>,
{ {
let puc = match &mut context { let puc = match &mut context {
Some(v) => core::ptr::from_mut::<ucontext_t>(*v) as *mut c_void, Some(v) => ptr::from_mut::<ucontext_t>(*v) as *mut c_void,
None => core::ptr::null_mut(), None => ptr::null_mut(),
}; };
libafl_qemu_handle_crash(signal as i32, info, puc); libafl_qemu_handle_crash(signal as i32, info, puc);
} }

View File

@ -8,6 +8,7 @@ use alloc::{alloc::alloc_zeroed, boxed::Box, vec::Vec};
use core::{ use core::{
alloc::Layout, alloc::Layout,
fmt::{self, Debug, Formatter}, fmt::{self, Debug, Formatter},
mem, ptr, slice,
}; };
use libafl::{ use libafl::{
@ -480,10 +481,7 @@ impl Serialize for AFLppCmpLogMap {
S: Serializer, S: Serializer,
{ {
let slice = unsafe { let slice = unsafe {
core::slice::from_raw_parts( slice::from_raw_parts(ptr::from_ref(self) as *const u8, mem::size_of::<Self>())
(core::ptr::from_ref::<Self>(self)) as *const u8,
core::mem::size_of::<Self>(),
)
}; };
serializer.serialize_bytes(slice) serializer.serialize_bytes(slice)
} }

View File

@ -65,7 +65,7 @@ fn libnoaslr() -> Result<()> {
libc::P_PID, libc::P_PID,
0, 0,
libc::PROC_ASLR_CTL, libc::PROC_ASLR_CTL,
&mut status as *mut i32 as *mut libc::c_void, &mut core::ptr::from_mut(status) as *mut libc::c_void,
) < 0 ) < 0
{ {
return Err(anyhow!("Failed to set aslr control")); return Err(anyhow!("Failed to set aslr control"));

View File

@ -36,7 +36,7 @@ fn disable_aslr() -> Result<()> {
libc::P_PID, libc::P_PID,
0, 0,
libc::PROC_ASLR_CTL, libc::PROC_ASLR_CTL,
&mut status as *mut i32 as *mut libc::c_void, &mut core::ptr::from_mut(status) as *mut libc::c_void,
) )
}; };
if r < 0 { if r < 0 {