diff --git a/fuzzers/fuzzbench/src/bin/libafl_cc.rs b/fuzzers/fuzzbench/src/bin/libafl_cc.rs index b96e03f885..8c9e37f638 100644 --- a/fuzzers/fuzzbench/src/bin/libafl_cc.rs +++ b/fuzzers/fuzzbench/src/bin/libafl_cc.rs @@ -22,7 +22,7 @@ pub fn main() { .silence(true) // add arguments only if --libafl or --libafl-no-link are present .need_libafl_arg(true) - .from_args(&args) + .parse_args(&args) .expect("Failed to parse the command line") .link_staticlib(&dir, "fuzzbench") .add_arg("-fsanitize-coverage=trace-pc-guard,trace-cmp") diff --git a/fuzzers/generic_inmemory/src/bin/libafl_cc.rs b/fuzzers/generic_inmemory/src/bin/libafl_cc.rs index a45c3fea9a..518f27a081 100644 --- a/fuzzers/generic_inmemory/src/bin/libafl_cc.rs +++ b/fuzzers/generic_inmemory/src/bin/libafl_cc.rs @@ -20,7 +20,7 @@ pub fn main() { .cpp(is_cpp) // silence the compiler wrapper output, needed for some configure scripts. .silence(true) - .from_args(&args) + .parse_args(&args) .expect("Failed to parse the command line") .link_staticlib(&dir, "generic_inmemory") .add_arg("-fsanitize-coverage=trace-pc-guard,trace-cmp") diff --git a/fuzzers/libfuzzer_libmozjpeg/src/bin/libafl_cc.rs b/fuzzers/libfuzzer_libmozjpeg/src/bin/libafl_cc.rs index f4ebb8a4b9..359ad30eab 100644 --- a/fuzzers/libfuzzer_libmozjpeg/src/bin/libafl_cc.rs +++ b/fuzzers/libfuzzer_libmozjpeg/src/bin/libafl_cc.rs @@ -20,7 +20,7 @@ pub fn main() { .cpp(is_cpp) // silence the compiler wrapper output, needed for some configure scripts. .silence(true) - .from_args(&args) + .parse_args(&args) .expect("Failed to parse the command line") .link_staticlib(&dir, "libfuzzer_libmozjpeg") .add_arg("-fsanitize-coverage=trace-pc-guard,trace-cmp") diff --git a/fuzzers/libfuzzer_libpng/src/bin/libafl_cc.rs b/fuzzers/libfuzzer_libpng/src/bin/libafl_cc.rs index a860154614..3c00818ff1 100644 --- a/fuzzers/libfuzzer_libpng/src/bin/libafl_cc.rs +++ b/fuzzers/libfuzzer_libpng/src/bin/libafl_cc.rs @@ -20,7 +20,7 @@ pub fn main() { .cpp(is_cpp) // silence the compiler wrapper output, needed for some configure scripts. .silence(true) - .from_args(&args) + .parse_args(&args) .expect("Failed to parse the command line") .link_staticlib(&dir, "libfuzzer_libpng") .add_arg("-fsanitize-coverage=trace-pc-guard") diff --git a/fuzzers/libfuzzer_libpng_ctx/src/bin/libafl_cc.rs b/fuzzers/libfuzzer_libpng_ctx/src/bin/libafl_cc.rs index b3fa85f501..cd2b355dc2 100644 --- a/fuzzers/libfuzzer_libpng_ctx/src/bin/libafl_cc.rs +++ b/fuzzers/libfuzzer_libpng_ctx/src/bin/libafl_cc.rs @@ -20,7 +20,7 @@ pub fn main() { .cpp(is_cpp) // silence the compiler wrapper output, needed for some configure scripts. .silence(true) - .from_args(&args) + .parse_args(&args) .expect("Failed to parse the command line") .add_pass(LLVMPasses::AFLCoverage) .add_arg("-mllvm") diff --git a/fuzzers/libfuzzer_libpng_launcher/src/bin/libafl_cc.rs b/fuzzers/libfuzzer_libpng_launcher/src/bin/libafl_cc.rs index a860154614..3c00818ff1 100644 --- a/fuzzers/libfuzzer_libpng_launcher/src/bin/libafl_cc.rs +++ b/fuzzers/libfuzzer_libpng_launcher/src/bin/libafl_cc.rs @@ -20,7 +20,7 @@ pub fn main() { .cpp(is_cpp) // silence the compiler wrapper output, needed for some configure scripts. .silence(true) - .from_args(&args) + .parse_args(&args) .expect("Failed to parse the command line") .link_staticlib(&dir, "libfuzzer_libpng") .add_arg("-fsanitize-coverage=trace-pc-guard") diff --git a/fuzzers/libfuzzer_reachability/src/bin/libafl_cc.rs b/fuzzers/libfuzzer_reachability/src/bin/libafl_cc.rs index c2d060aa0f..36df36d368 100644 --- a/fuzzers/libfuzzer_reachability/src/bin/libafl_cc.rs +++ b/fuzzers/libfuzzer_reachability/src/bin/libafl_cc.rs @@ -21,7 +21,7 @@ pub fn main() { .cpp(is_cpp) // silence the compiler wrapper output, needed for some configure scripts. .silence(true) - .from_args(&args) + .parse_args(&args) .expect("Failed to parse the command line") .add_link_arg(weak) .link_staticlib(&dir, "libfuzzer_libpng") diff --git a/fuzzers/tutorial/src/bin/libafl_cc.rs b/fuzzers/tutorial/src/bin/libafl_cc.rs index ead1f07c88..f7ccaabae3 100644 --- a/fuzzers/tutorial/src/bin/libafl_cc.rs +++ b/fuzzers/tutorial/src/bin/libafl_cc.rs @@ -20,7 +20,7 @@ pub fn main() { .cpp(is_cpp) // silence the compiler wrapper output, needed for some configure scripts. .silence(true) - .from_args(&args) + .parse_args(&args) .expect("Failed to parse the command line") .link_staticlib(&dir, "tutorial") .add_arg("-fsanitize-coverage=trace-pc-guard") diff --git a/libafl/src/bolts/llmp.rs b/libafl/src/bolts/llmp.rs index de7b75a189..6b4e6519cc 100644 --- a/libafl/src/bolts/llmp.rs +++ b/libafl/src/bolts/llmp.rs @@ -1272,7 +1272,7 @@ where ) -> Result { Self::on_existing_map( shmem_provider.clone(), - shmem_provider.from_description(description.shmem)?, + shmem_provider.map_from_decription(description.shmem)?, description.last_message_offset, ) } @@ -1431,7 +1431,7 @@ where // Map the new page. The old one should be unmapped by Drop self.current_recv_map = - LlmpSharedMap::existing(self.shmem_provider.from_id_and_size( + LlmpSharedMap::existing(self.shmem_provider.map_from_id_and_size( ShMemId::from_slice(&pageinfo_cpy.shm_str), pageinfo_cpy.map_size, )?); @@ -1546,7 +1546,7 @@ where ) -> Result { Self::on_existing_map( shmem_provider.clone(), - shmem_provider.from_description(description.shmem)?, + shmem_provider.map_from_decription(description.shmem)?, description.last_message_offset, ) } @@ -1855,7 +1855,7 @@ where )?; let new_map = - LlmpSharedMap::existing(self.shmem_provider.from_description(map_description)?); + LlmpSharedMap::existing(self.shmem_provider.map_from_decription(map_description)?); { self.register_client(new_map); @@ -2207,7 +2207,7 @@ where last_msg_sent: ptr::null_mut(), out_maps: vec![LlmpSharedMap::existing( shmem_provider_bg - .from_description(tcp_out_map_description) + .map_from_decription(tcp_out_map_description) .unwrap(), )], // drop pages to the broker, if it already read them. @@ -2313,7 +2313,7 @@ where } else { let pageinfo = (*msg).buf.as_mut_ptr() as *mut LlmpPayloadSharedMapInfo; - match self.shmem_provider.from_id_and_size( + match self.shmem_provider.map_from_id_and_size( ShMemId::from_slice(&(*pageinfo).shm_str), (*pageinfo).map_size, ) { @@ -2638,7 +2638,8 @@ where )); }; - let map = LlmpSharedMap::existing(shmem_provider.from_description(broker_map_description)?); + let map = + LlmpSharedMap::existing(shmem_provider.map_from_decription(broker_map_description)?); let mut ret = Self::new(shmem_provider, map)?; let client_hello_req = TcpRequest::LocalClientHello { diff --git a/libafl/src/bolts/os/unix_shmem_server.rs b/libafl/src/bolts/os/unix_shmem_server.rs index 8096559aa5..0494814944 100644 --- a/libafl/src/bolts/os/unix_shmem_server.rs +++ b/libafl/src/bolts/os/unix_shmem_server.rs @@ -9,7 +9,7 @@ use crate::{ bolts::shmem::{ShMem, ShMemDescription, ShMemId, ShMemProvider}, Error, }; -use core::mem::ManuallyDrop; +use core::{mem::ManuallyDrop, ptr::addr_of}; use hashbrown::HashMap; use serde::{Deserialize, Serialize}; use std::{ @@ -177,14 +177,16 @@ where Ok(ServedShMem { inner: ManuallyDrop::new( - self.inner - .from_id_and_size(ShMemId::from_string(&format!("{}", client_fd)), map_size)?, + self.inner.map_from_id_and_size( + ShMemId::from_string(&format!("{}", client_fd)), + map_size, + )?, ), server_fd, }) } - fn from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result { + fn map_from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result { let parts = id.as_str().split(':').collect::>(); let server_id_str = parts.get(0).unwrap(); let (server_fd, client_fd) = self.send_receive(ServedShMemRequest::ExistingMap( @@ -193,7 +195,7 @@ where Ok(ServedShMem { inner: ManuallyDrop::new( self.inner - .from_id_and_size(ShMemId::from_string(&format!("{}", client_fd)), size)?, + .map_from_id_and_size(ShMemId::from_string(&format!("{}", client_fd)), size)?, ), server_fd, }) @@ -649,8 +651,7 @@ where let copied_poll_fds: Vec = poll_fds.clone(); for poll_fd in copied_poll_fds { let revents = poll_fd.revents().expect("revents should not be None"); - let raw_polled_fd = - unsafe { *((&poll_fd as *const PollFd) as *const libc::pollfd) }.fd; + let raw_polled_fd = unsafe { *((addr_of!(poll_fd)) as *const libc::pollfd) }.fd; if revents.contains(PollFlags::POLLHUP) { poll_fds.remove(poll_fds.iter().position(|item| *item == poll_fd).unwrap()); self.clients.remove(&raw_polled_fd); diff --git a/libafl/src/bolts/os/unix_signals.rs b/libafl/src/bolts/os/unix_signals.rs index e8f9d56957..ca9b093049 100644 --- a/libafl/src/bolts/os/unix_signals.rs +++ b/libafl/src/bolts/os/unix_signals.rs @@ -4,7 +4,7 @@ use core::{ cell::UnsafeCell, fmt::{self, Display, Formatter}, mem, ptr, - ptr::write_volatile, + ptr::{addr_of_mut, write_volatile}, sync::atomic::{compiler_fence, Ordering}, }; @@ -214,11 +214,11 @@ pub unsafe fn setup_signal_handler(handler: &mut T) -> Res let mut ss: stack_t = mem::zeroed(); ss.ss_size = SIGNAL_STACK_SIZE; ss.ss_sp = SIGNAL_STACK_PTR; - sigaltstack(&mut ss as *mut stack_t, ptr::null_mut() as _); + sigaltstack(addr_of_mut!(ss), ptr::null_mut() as _); let mut sa: sigaction = mem::zeroed(); - sigemptyset(&mut sa.sa_mask as *mut libc::sigset_t); - sigaddset(&mut sa.sa_mask as *mut libc::sigset_t, SIGALRM); + sigemptyset(addr_of_mut!(sa.sa_mask)); + sigaddset(addr_of_mut!(sa.sa_mask), SIGALRM); sa.sa_flags = SA_NODEFER | SA_SIGINFO | SA_ONSTACK; sa.sa_sigaction = handle_signal as usize; let signals = handler.signals(); @@ -230,7 +230,7 @@ pub unsafe fn setup_signal_handler(handler: &mut T) -> Res }), ); - if sigaction(sig as i32, &mut sa as *mut sigaction, ptr::null_mut()) < 0 { + if sigaction(sig as i32, addr_of_mut!(sa), ptr::null_mut()) < 0 { #[cfg(feature = "std")] { let err_str = CString::new(format!("Failed to setup {} handler", sig)).unwrap(); diff --git a/libafl/src/bolts/serdeany.rs b/libafl/src/bolts/serdeany.rs index ed6afd3825..8cea851276 100644 --- a/libafl/src/bolts/serdeany.rs +++ b/libafl/src/bolts/serdeany.rs @@ -6,6 +6,7 @@ use alloc::boxed::Box; use core::{ any::{Any, TypeId}, fmt::Debug, + ptr::addr_of, }; // yolo @@ -18,7 +19,7 @@ use core::{ #[must_use] pub fn pack_type_id(id: u64) -> TypeId { assert_eq_size!(TypeId, u64); - unsafe { *(&id as *const u64 as *const TypeId) } + unsafe { *(addr_of!(id) as *const TypeId) } } /// Unpack a `type_id` to an `u64` @@ -29,7 +30,7 @@ pub fn pack_type_id(id: u64) -> TypeId { #[must_use] pub fn unpack_type_id(id: TypeId) -> u64 { assert_eq_size!(TypeId, u64); - unsafe { *(&id as *const _ as *const u64) } + unsafe { *(addr_of!(id) as *const u64) } } /// A (de)serializable Any trait diff --git a/libafl/src/bolts/shmem.rs b/libafl/src/bolts/shmem.rs index 83f9c7048f..e461420faa 100644 --- a/libafl/src/bolts/shmem.rs +++ b/libafl/src/bolts/shmem.rs @@ -215,16 +215,16 @@ pub trait ShMemProvider: Clone + Default + Debug { fn new_map(&mut self, map_size: usize) -> Result; /// Get a mapping given its id and size - fn from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result; + fn map_from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result; /// Get a mapping given a description - fn from_description(&mut self, description: ShMemDescription) -> Result { - self.from_id_and_size(description.id, description.size) + fn map_from_decription(&mut self, description: ShMemDescription) -> Result { + self.map_from_id_and_size(description.id, description.size) } /// Create a new sharedmap reference from an existing `id` and `len` fn clone_ref(&mut self, mapping: &Self::Mem) -> Result { - self.from_id_and_size(mapping.id(), mapping.len()) + self.map_from_id_and_size(mapping.id(), mapping.len()) } /// Reads an existing map config from env vars, then maps it @@ -232,7 +232,7 @@ pub trait ShMemProvider: Clone + Default + Debug { fn existing_from_env(&mut self, env_name: &str) -> Result { let map_shm_str = env::var(env_name)?; let map_size = str::parse::(&env::var(format!("{}_SIZE", env_name))?)?; - self.from_description(ShMemDescription::from_string_and_size( + self.map_from_decription(ShMemDescription::from_string_and_size( &map_shm_str, map_size, )) @@ -342,9 +342,9 @@ where }) } - fn from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result { + fn map_from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result { Ok(Self::Mem { - internal: ManuallyDrop::new(self.internal.borrow_mut().from_id_and_size(id, size)?), + internal: ManuallyDrop::new(self.internal.borrow_mut().map_from_id_and_size(id, size)?), provider: self.internal.clone(), }) } @@ -622,7 +622,7 @@ pub mod unix_shmem { } } - fn from_id_and_size(id: ShMemId, map_size: usize) -> Result { + fn map_from_id_and_size(id: ShMemId, map_size: usize) -> Result { unsafe { let shm_fd: i32 = id.to_string().parse().unwrap(); @@ -684,8 +684,12 @@ pub mod unix_shmem { MmapShMem::new(map_size, self.current_map_id) } - fn from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result { - MmapShMem::from_id_and_size(id, size) + fn map_from_id_and_size( + &mut self, + id: ShMemId, + size: usize, + ) -> Result { + MmapShMem::map_from_id_and_size(id, size) } } @@ -771,7 +775,7 @@ pub mod unix_shmem { } /// Get a [`UnixShMem`] of the existing shared memory mapping identified by id - pub fn from_id_and_size(id: ShMemId, map_size: usize) -> Result { + pub fn map_from_id_and_size(id: ShMemId, map_size: usize) -> Result { unsafe { let id_int: i32 = id.into(); let map = shmat(id_int, ptr::null(), 0) as *mut c_uchar; @@ -843,8 +847,12 @@ pub mod unix_shmem { CommonUnixShMem::new(map_size) } - fn from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result { - CommonUnixShMem::from_id_and_size(id, size) + fn map_from_id_and_size( + &mut self, + id: ShMemId, + size: usize, + ) -> Result { + CommonUnixShMem::map_from_id_and_size(id, size) } } } @@ -951,7 +959,7 @@ pub mod unix_shmem { } /// Get a [`crate::bolts::shmem::unix_shmem::UnixShMem`] of the existing [`ShMem`] mapping identified by id. - pub fn from_id_and_size(id: ShMemId, map_size: usize) -> Result { + pub fn map_from_id_and_size(id: ShMemId, map_size: usize) -> Result { unsafe { let fd: i32 = id.to_string().parse().unwrap(); #[allow(trivial_numeric_casts, clippy::cast_sign_loss)] @@ -1055,8 +1063,12 @@ pub mod unix_shmem { Ok(mapping) } - fn from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result { - AshmemShMem::from_id_and_size(id, size) + fn map_from_id_and_size( + &mut self, + id: ShMemId, + size: usize, + ) -> Result { + AshmemShMem::map_from_id_and_size(id, size) } } } @@ -1147,7 +1159,7 @@ pub mod win32_shmem { } } - fn from_id_and_size(id: ShMemId, map_size: usize) -> Result { + fn map_from_id_and_size(id: ShMemId, map_size: usize) -> Result { unsafe { let map_str_bytes = id.id; // Unlike MapViewOfFile this one needs u32 @@ -1228,8 +1240,8 @@ pub mod win32_shmem { Win32ShMem::new_map(map_size) } - fn from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result { - Win32ShMem::from_id_and_size(id, size) + fn map_from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result { + Win32ShMem::map_from_id_and_size(id, size) } } } diff --git a/libafl/src/bolts/tuples.rs b/libafl/src/bolts/tuples.rs index 071668f294..4f9e5db0bf 100644 --- a/libafl/src/bolts/tuples.rs +++ b/libafl/src/bolts/tuples.rs @@ -2,7 +2,10 @@ pub use tuple_list::{tuple_list, tuple_list_type, TupleList}; -use core::any::TypeId; +use core::{ + any::TypeId, + ptr::{addr_of, addr_of_mut}, +}; use xxhash_rust::xxh3::xxh3_64; @@ -142,7 +145,7 @@ where { fn match_first_type(&self) -> Option<&T> { if TypeId::of::() == TypeId::of::() { - unsafe { (&self.0 as *const _ as *const T).as_ref() } + unsafe { (addr_of!(self.0) as *const T).as_ref() } } else { self.1.match_first_type::() } @@ -150,7 +153,7 @@ where fn match_first_type_mut(&mut self) -> Option<&mut T> { if TypeId::of::() == TypeId::of::() { - unsafe { (&mut self.0 as *mut _ as *mut T).as_mut() } + unsafe { (addr_of_mut!(self.0) as *mut T).as_mut() } } else { self.1.match_first_type_mut::() } @@ -178,7 +181,7 @@ where fn match_type(&self, f: fn(t: &T)) { // Switch this check to https://stackoverflow.com/a/60138532/7658998 when in stable and remove 'static if TypeId::of::() == TypeId::of::() { - f(unsafe { (&self.0 as *const _ as *const T).as_ref() }.unwrap()); + f(unsafe { (addr_of!(self.0) as *const T).as_ref() }.unwrap()); } self.1.match_type::(f); } @@ -186,7 +189,7 @@ where fn match_type_mut(&mut self, f: fn(t: &mut T)) { // Switch this check to https://stackoverflow.com/a/60138532/7658998 when in stable and remove 'static if TypeId::of::() == TypeId::of::() { - f(unsafe { (&mut self.0 as *mut _ as *mut T).as_mut() }.unwrap()); + f(unsafe { (addr_of_mut!(self.0) as *mut T).as_mut() }.unwrap()); } self.1.match_type_mut::(f); } @@ -251,7 +254,7 @@ where { fn match_name(&self, name: &str) -> Option<&T> { if type_eq::() && name == self.0.name() { - unsafe { (&self.0 as *const _ as *const T).as_ref() } + unsafe { (addr_of!(self.0) as *const T).as_ref() } } else { self.1.match_name::(name) } @@ -259,7 +262,7 @@ where fn match_name_mut(&mut self, name: &str) -> Option<&mut T> { if type_eq::() && name == self.0.name() { - unsafe { (&mut self.0 as *mut _ as *mut T).as_mut() } + unsafe { (addr_of_mut!(self.0) as *mut T).as_mut() } } else { self.1.match_name_mut::(name) } @@ -291,7 +294,7 @@ where fn match_name_type(&self, name: &str) -> Option<&T> { // Switch this check to https://stackoverflow.com/a/60138532/7658998 when in stable and remove 'static if TypeId::of::() == TypeId::of::() && name == self.0.name() { - unsafe { (&self.0 as *const _ as *const T).as_ref() } + unsafe { (addr_of!(self.0) as *const T).as_ref() } } else { self.1.match_name_type::(name) } @@ -300,7 +303,7 @@ where fn match_name_type_mut(&mut self, name: &str) -> Option<&mut T> { // Switch this check to https://stackoverflow.com/a/60138532/7658998 when in stable and remove 'static if TypeId::of::() == TypeId::of::() && name == self.0.name() { - unsafe { (&mut self.0 as *mut _ as *mut T).as_mut() } + unsafe { (addr_of_mut!(self.0) as *mut T).as_mut() } } else { self.1.match_name_type_mut::(name) } diff --git a/libafl/src/events/llmp.rs b/libafl/src/events/llmp.rs index 5321e46ded..61fb2bd9dd 100644 --- a/libafl/src/events/llmp.rs +++ b/libafl/src/events/llmp.rs @@ -868,9 +868,9 @@ where compiler_fence(Ordering::SeqCst); + #[allow(clippy::manual_assert)] if !staterestorer.has_content() { #[cfg(unix)] - #[allow(clippy::manual_assert)] if child_status == 137 { // Out of Memory, see https://tldp.org/LDP/abs/html/exitcodes.html // and https://github.com/AFLplusplus/LibAFL/issues/32 for discussion. diff --git a/libafl/src/events/simple.rs b/libafl/src/events/simple.rs index 3fbd6983cb..131d6c7ab2 100644 --- a/libafl/src/events/simple.rs +++ b/libafl/src/events/simple.rs @@ -366,9 +366,9 @@ where compiler_fence(Ordering::SeqCst); + #[allow(clippy::manual_assert)] if !staterestorer.has_content() { #[cfg(unix)] - #[allow(clippy::manual_assert)] if child_status == 137 { // Out of Memory, see https://tldp.org/LDP/abs/html/exitcodes.html // and https://github.com/AFLplusplus/LibAFL/issues/32 for discussion. diff --git a/libafl/src/stages/concolic.rs b/libafl/src/stages/concolic.rs index a8250eee42..299597d854 100644 --- a/libafl/src/stages/concolic.rs +++ b/libafl/src/stages/concolic.rs @@ -95,7 +95,6 @@ use crate::monitors::PerfFeature; #[cfg(feature = "concolic_mutation")] #[allow(clippy::too_many_lines)] fn generate_mutations(iter: impl Iterator) -> Vec> { - use core::mem::size_of; use hashbrown::HashMap; use z3::{ ast::{Ast, Bool, Dynamic, BV}, @@ -168,9 +167,7 @@ fn generate_mutations(iter: impl Iterator) -> Vec< Some(BV::from_u64(&ctx, value, u32::from(bits)).into()) } SymExpr::Integer128 { high: _, low: _ } => todo!(), - SymExpr::NullPointer => { - Some(BV::from_u64(&ctx, 0, (8 * size_of::()) as u32).into()) - } + SymExpr::NullPointer => Some(BV::from_u64(&ctx, 0, usize::BITS).into()), SymExpr::True => Some(Bool::from_bool(&ctx, true).into()), SymExpr::False => Some(Bool::from_bool(&ctx, false).into()), SymExpr::Bool { value } => Some(Bool::from_bool(&ctx, value).into()), diff --git a/libafl_cc/src/clang.rs b/libafl_cc/src/clang.rs index 7b42a906e3..b6d77dbdf8 100644 --- a/libafl_cc/src/clang.rs +++ b/libafl_cc/src/clang.rs @@ -63,7 +63,7 @@ pub struct ClangWrapper { need_libafl_arg: bool, has_libafl_arg: bool, - from_args_called: bool, + parse_args_called: bool, base_args: Vec, cc_args: Vec, link_args: Vec, @@ -72,7 +72,7 @@ pub struct ClangWrapper { #[allow(clippy::match_same_arms)] // for the linking = false wip for "shared" impl CompilerWrapper for ClangWrapper { - fn from_args(&mut self, args: &[S]) -> Result<&'_ mut Self, Error> + fn parse_args(&mut self, args: &[S]) -> Result<&'_ mut Self, Error> where S: AsRef, { @@ -83,13 +83,13 @@ impl CompilerWrapper for ClangWrapper { )); } - if self.from_args_called { + if self.parse_args_called { return Err(Error::Unknown( - "CompilerWrapper::from_args cannot be called twice on the same instance" + "CompilerWrapper::parse_args cannot be called twice on the same instance" .to_string(), )); } - self.from_args_called = true; + self.parse_args_called = true; if args.len() == 1 { return Err(Error::InvalidArguments( @@ -283,7 +283,7 @@ impl ClangWrapper { bit_mode: 0, need_libafl_arg: false, has_libafl_arg: false, - from_args_called: false, + parse_args_called: false, base_args: vec![], cc_args: vec![], link_args: vec![], @@ -342,7 +342,7 @@ mod tests { #[test] fn test_clang_version() { if let Err(res) = ClangWrapper::new() - .from_args(&["my-clang", "-v"]) + .parse_args(&["my-clang", "-v"]) .unwrap() .run() { diff --git a/libafl_cc/src/lib.rs b/libafl_cc/src/lib.rs index 2a15b8ca04..910e9887d3 100644 --- a/libafl_cc/src/lib.rs +++ b/libafl_cc/src/lib.rs @@ -90,7 +90,7 @@ pub const LIB_PREFIX: &str = "lib"; /// Wrap a compiler hijacking its arguments pub trait CompilerWrapper { /// Set the wrapper arguments parsing a command line set of arguments - fn from_args(&mut self, args: &[S]) -> Result<&'_ mut Self, Error> + fn parse_args(&mut self, args: &[S]) -> Result<&'_ mut Self, Error> where S: AsRef; diff --git a/libafl_frida/src/asan/asan_rt.rs b/libafl_frida/src/asan/asan_rt.rs index af4cc11480..1075c2c396 100644 --- a/libafl_frida/src/asan/asan_rt.rs +++ b/libafl_frida/src/asan/asan_rt.rs @@ -7,7 +7,10 @@ this helps finding mem errors early. */ use backtrace::Backtrace; -use core::fmt::{self, Debug, Formatter}; +use core::{ + fmt::{self, Debug, Formatter}, + ptr::addr_of_mut, +}; use frida_gum::{ModuleDetails, NativePointer, RangeDetails}; use hashbrown::HashMap; use nix::sys::mman::{mmap, MapFlags, ProtFlags}; @@ -362,7 +365,7 @@ impl AsanRuntime { rlim_cur: 0, rlim_max: 0, }; - assert!(unsafe { getrlimit(RLIMIT_STACK, &mut stack_rlimit as *mut rlimit) } == 0); + assert!(unsafe { getrlimit(RLIMIT_STACK, addr_of_mut!(stack_rlimit)) } == 0); stack_rlimit.rlim_cur as usize } @@ -387,7 +390,7 @@ impl AsanRuntime { #[must_use] pub fn current_stack() -> (usize, usize) { let mut stack_var = 0xeadbeef; - let stack_address = &mut stack_var as *mut _ as *mut c_void as usize; + let stack_address = addr_of_mut!(stack_var) as usize; let range_details = RangeDetails::with_address(stack_address as u64).unwrap(); // Write something to (hopefully) make sure the val isn't optimized out unsafe { @@ -1853,7 +1856,7 @@ impl AsanRuntime { ; self_addr: ; .qword self as *mut _ as *mut c_void as i64 ; self_regs_addr: - ; .qword &mut self.regs as *mut _ as *mut c_void as i64 + ; .qword addr_of_mut!(self.regs) as i64 ; trap_func: ; .qword AsanRuntime::handle_trap as *mut c_void as i64 ); diff --git a/libafl_frida/src/coverage_rt.rs b/libafl_frida/src/coverage_rt.rs index a2bf1c7305..3a823277f9 100644 --- a/libafl_frida/src/coverage_rt.rs +++ b/libafl_frida/src/coverage_rt.rs @@ -1,6 +1,6 @@ //! Functionality regarding binary-only coverage collection. +use core::ptr::addr_of_mut; use dynasmrt::{dynasm, DynasmApi, DynasmLabelApi}; -use std::ffi::c_void; #[cfg(target_arch = "x86_64")] use frida_gum::instruction_writer::X86Register; @@ -116,7 +116,7 @@ impl CoverageRuntime { ; popfq ; ret ;map_addr: - ;.qword &mut self.map as *mut _ as *mut c_void as i64 + ;.qword addr_of_mut!(self.map) as i64 ;previous_loc: ;.qword 0 ); @@ -152,7 +152,7 @@ impl CoverageRuntime { self.current_log_impl = writer.pc(); writer.put_bytes(self.blob_maybe_log()); - let prev_loc_pointer = &mut self.previous_pc as *mut _ as u64; // Get the pointer to self.previous_pc + let prev_loc_pointer = addr_of_mut!(self.previous_pc) as u64; // Get the pointer to self.previous_pc writer.put_bytes(&prev_loc_pointer.to_ne_bytes()); diff --git a/libafl_targets/src/drcov.rs b/libafl_targets/src/drcov.rs index ae480c6877..474335ad3a 100644 --- a/libafl_targets/src/drcov.rs +++ b/libafl_targets/src/drcov.rs @@ -2,6 +2,7 @@ //! writing basic-block trace files to be read by coverage analysis tools, such as [Lighthouse](https://github.com/gaasedelen/lighthouse), //! [bncov](https://github.com/ForAllSecure/bncov), [dragondance](https://github.com/0ffffffffh/dragondance), etc. +use core::ptr::addr_of; use libafl::Error; use rangemap::RangeMap; use std::{ @@ -97,7 +98,7 @@ impl<'a> DrCovWriter<'a> { }; writer .write_all(unsafe { - std::slice::from_raw_parts(&basic_block as *const _ as *const u8, 8) + std::slice::from_raw_parts(addr_of!(basic_block) as *const u8, 8) }) .unwrap(); } diff --git a/libafl_targets/src/libfuzzer.rs b/libafl_targets/src/libfuzzer.rs index 60fda5d613..f912a591b5 100644 --- a/libafl_targets/src/libfuzzer.rs +++ b/libafl_targets/src/libfuzzer.rs @@ -23,10 +23,8 @@ pub fn libfuzzer_initialize(args: &[String]) -> i32 { #[allow(clippy::cast_possible_wrap)] let argc = argv.len() as i32; unsafe { - libafl_targets_libfuzzer_init( - &argc as *const i32, - &argv.as_ptr() as *const *const *const u8, - ) + let argv_ptr = argv.as_ptr(); + libafl_targets_libfuzzer_init(core::ptr::addr_of!(argc), core::ptr::addr_of!(argv_ptr)) } }