Clippy fixes for latest toolchain (#471)

* from warning

* fix latest clippy

* clippy fixes++

* more nits
This commit is contained in:
Dominik Maier 2022-01-17 11:02:42 +01:00 committed by GitHub
parent aebd85f041
commit 2dd88998bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 100 additions and 83 deletions

View File

@ -22,7 +22,7 @@ pub fn main() {
.silence(true) .silence(true)
// add arguments only if --libafl or --libafl-no-link are present // add arguments only if --libafl or --libafl-no-link are present
.need_libafl_arg(true) .need_libafl_arg(true)
.from_args(&args) .parse_args(&args)
.expect("Failed to parse the command line") .expect("Failed to parse the command line")
.link_staticlib(&dir, "fuzzbench") .link_staticlib(&dir, "fuzzbench")
.add_arg("-fsanitize-coverage=trace-pc-guard,trace-cmp") .add_arg("-fsanitize-coverage=trace-pc-guard,trace-cmp")

View File

@ -20,7 +20,7 @@ pub fn main() {
.cpp(is_cpp) .cpp(is_cpp)
// silence the compiler wrapper output, needed for some configure scripts. // silence the compiler wrapper output, needed for some configure scripts.
.silence(true) .silence(true)
.from_args(&args) .parse_args(&args)
.expect("Failed to parse the command line") .expect("Failed to parse the command line")
.link_staticlib(&dir, "generic_inmemory") .link_staticlib(&dir, "generic_inmemory")
.add_arg("-fsanitize-coverage=trace-pc-guard,trace-cmp") .add_arg("-fsanitize-coverage=trace-pc-guard,trace-cmp")

View File

@ -20,7 +20,7 @@ pub fn main() {
.cpp(is_cpp) .cpp(is_cpp)
// silence the compiler wrapper output, needed for some configure scripts. // silence the compiler wrapper output, needed for some configure scripts.
.silence(true) .silence(true)
.from_args(&args) .parse_args(&args)
.expect("Failed to parse the command line") .expect("Failed to parse the command line")
.link_staticlib(&dir, "libfuzzer_libmozjpeg") .link_staticlib(&dir, "libfuzzer_libmozjpeg")
.add_arg("-fsanitize-coverage=trace-pc-guard,trace-cmp") .add_arg("-fsanitize-coverage=trace-pc-guard,trace-cmp")

View File

@ -20,7 +20,7 @@ pub fn main() {
.cpp(is_cpp) .cpp(is_cpp)
// silence the compiler wrapper output, needed for some configure scripts. // silence the compiler wrapper output, needed for some configure scripts.
.silence(true) .silence(true)
.from_args(&args) .parse_args(&args)
.expect("Failed to parse the command line") .expect("Failed to parse the command line")
.link_staticlib(&dir, "libfuzzer_libpng") .link_staticlib(&dir, "libfuzzer_libpng")
.add_arg("-fsanitize-coverage=trace-pc-guard") .add_arg("-fsanitize-coverage=trace-pc-guard")

View File

@ -20,7 +20,7 @@ pub fn main() {
.cpp(is_cpp) .cpp(is_cpp)
// silence the compiler wrapper output, needed for some configure scripts. // silence the compiler wrapper output, needed for some configure scripts.
.silence(true) .silence(true)
.from_args(&args) .parse_args(&args)
.expect("Failed to parse the command line") .expect("Failed to parse the command line")
.add_pass(LLVMPasses::AFLCoverage) .add_pass(LLVMPasses::AFLCoverage)
.add_arg("-mllvm") .add_arg("-mllvm")

View File

@ -20,7 +20,7 @@ pub fn main() {
.cpp(is_cpp) .cpp(is_cpp)
// silence the compiler wrapper output, needed for some configure scripts. // silence the compiler wrapper output, needed for some configure scripts.
.silence(true) .silence(true)
.from_args(&args) .parse_args(&args)
.expect("Failed to parse the command line") .expect("Failed to parse the command line")
.link_staticlib(&dir, "libfuzzer_libpng") .link_staticlib(&dir, "libfuzzer_libpng")
.add_arg("-fsanitize-coverage=trace-pc-guard") .add_arg("-fsanitize-coverage=trace-pc-guard")

View File

@ -21,7 +21,7 @@ pub fn main() {
.cpp(is_cpp) .cpp(is_cpp)
// silence the compiler wrapper output, needed for some configure scripts. // silence the compiler wrapper output, needed for some configure scripts.
.silence(true) .silence(true)
.from_args(&args) .parse_args(&args)
.expect("Failed to parse the command line") .expect("Failed to parse the command line")
.add_link_arg(weak) .add_link_arg(weak)
.link_staticlib(&dir, "libfuzzer_libpng") .link_staticlib(&dir, "libfuzzer_libpng")

View File

@ -20,7 +20,7 @@ pub fn main() {
.cpp(is_cpp) .cpp(is_cpp)
// silence the compiler wrapper output, needed for some configure scripts. // silence the compiler wrapper output, needed for some configure scripts.
.silence(true) .silence(true)
.from_args(&args) .parse_args(&args)
.expect("Failed to parse the command line") .expect("Failed to parse the command line")
.link_staticlib(&dir, "tutorial") .link_staticlib(&dir, "tutorial")
.add_arg("-fsanitize-coverage=trace-pc-guard") .add_arg("-fsanitize-coverage=trace-pc-guard")

View File

@ -1272,7 +1272,7 @@ where
) -> Result<Self, Error> { ) -> Result<Self, Error> {
Self::on_existing_map( Self::on_existing_map(
shmem_provider.clone(), shmem_provider.clone(),
shmem_provider.from_description(description.shmem)?, shmem_provider.map_from_decription(description.shmem)?,
description.last_message_offset, description.last_message_offset,
) )
} }
@ -1431,7 +1431,7 @@ where
// Map the new page. The old one should be unmapped by Drop // Map the new page. The old one should be unmapped by Drop
self.current_recv_map = 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), ShMemId::from_slice(&pageinfo_cpy.shm_str),
pageinfo_cpy.map_size, pageinfo_cpy.map_size,
)?); )?);
@ -1546,7 +1546,7 @@ where
) -> Result<Self, Error> { ) -> Result<Self, Error> {
Self::on_existing_map( Self::on_existing_map(
shmem_provider.clone(), shmem_provider.clone(),
shmem_provider.from_description(description.shmem)?, shmem_provider.map_from_decription(description.shmem)?,
description.last_message_offset, description.last_message_offset,
) )
} }
@ -1855,7 +1855,7 @@ where
)?; )?;
let new_map = 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); self.register_client(new_map);
@ -2207,7 +2207,7 @@ where
last_msg_sent: ptr::null_mut(), last_msg_sent: ptr::null_mut(),
out_maps: vec![LlmpSharedMap::existing( out_maps: vec![LlmpSharedMap::existing(
shmem_provider_bg shmem_provider_bg
.from_description(tcp_out_map_description) .map_from_decription(tcp_out_map_description)
.unwrap(), .unwrap(),
)], )],
// drop pages to the broker, if it already read them. // drop pages to the broker, if it already read them.
@ -2313,7 +2313,7 @@ where
} else { } else {
let pageinfo = (*msg).buf.as_mut_ptr() as *mut LlmpPayloadSharedMapInfo; 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), ShMemId::from_slice(&(*pageinfo).shm_str),
(*pageinfo).map_size, (*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 mut ret = Self::new(shmem_provider, map)?;
let client_hello_req = TcpRequest::LocalClientHello { let client_hello_req = TcpRequest::LocalClientHello {

View File

@ -9,7 +9,7 @@ use crate::{
bolts::shmem::{ShMem, ShMemDescription, ShMemId, ShMemProvider}, bolts::shmem::{ShMem, ShMemDescription, ShMemId, ShMemProvider},
Error, Error,
}; };
use core::mem::ManuallyDrop; use core::{mem::ManuallyDrop, ptr::addr_of};
use hashbrown::HashMap; use hashbrown::HashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{ use std::{
@ -177,14 +177,16 @@ where
Ok(ServedShMem { Ok(ServedShMem {
inner: ManuallyDrop::new( inner: ManuallyDrop::new(
self.inner self.inner.map_from_id_and_size(
.from_id_and_size(ShMemId::from_string(&format!("{}", client_fd)), map_size)?, ShMemId::from_string(&format!("{}", client_fd)),
map_size,
)?,
), ),
server_fd, server_fd,
}) })
} }
fn from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result<Self::Mem, Error> { fn map_from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result<Self::Mem, Error> {
let parts = id.as_str().split(':').collect::<Vec<&str>>(); let parts = id.as_str().split(':').collect::<Vec<&str>>();
let server_id_str = parts.get(0).unwrap(); let server_id_str = parts.get(0).unwrap();
let (server_fd, client_fd) = self.send_receive(ServedShMemRequest::ExistingMap( let (server_fd, client_fd) = self.send_receive(ServedShMemRequest::ExistingMap(
@ -193,7 +195,7 @@ where
Ok(ServedShMem { Ok(ServedShMem {
inner: ManuallyDrop::new( inner: ManuallyDrop::new(
self.inner 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, server_fd,
}) })
@ -649,8 +651,7 @@ where
let copied_poll_fds: Vec<PollFd> = poll_fds.clone(); let copied_poll_fds: Vec<PollFd> = poll_fds.clone();
for poll_fd in copied_poll_fds { for poll_fd in copied_poll_fds {
let revents = poll_fd.revents().expect("revents should not be None"); let revents = poll_fd.revents().expect("revents should not be None");
let raw_polled_fd = let raw_polled_fd = unsafe { *((addr_of!(poll_fd)) as *const libc::pollfd) }.fd;
unsafe { *((&poll_fd as *const PollFd) as *const libc::pollfd) }.fd;
if revents.contains(PollFlags::POLLHUP) { if revents.contains(PollFlags::POLLHUP) {
poll_fds.remove(poll_fds.iter().position(|item| *item == poll_fd).unwrap()); poll_fds.remove(poll_fds.iter().position(|item| *item == poll_fd).unwrap());
self.clients.remove(&raw_polled_fd); self.clients.remove(&raw_polled_fd);

View File

@ -4,7 +4,7 @@ use core::{
cell::UnsafeCell, cell::UnsafeCell,
fmt::{self, Display, Formatter}, fmt::{self, Display, Formatter},
mem, ptr, mem, ptr,
ptr::write_volatile, ptr::{addr_of_mut, write_volatile},
sync::atomic::{compiler_fence, Ordering}, sync::atomic::{compiler_fence, Ordering},
}; };
@ -214,11 +214,11 @@ pub unsafe fn setup_signal_handler<T: 'static + Handler>(handler: &mut T) -> Res
let mut ss: stack_t = mem::zeroed(); let mut ss: stack_t = mem::zeroed();
ss.ss_size = SIGNAL_STACK_SIZE; ss.ss_size = SIGNAL_STACK_SIZE;
ss.ss_sp = SIGNAL_STACK_PTR; 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(); let mut sa: sigaction = mem::zeroed();
sigemptyset(&mut sa.sa_mask as *mut libc::sigset_t); sigemptyset(addr_of_mut!(sa.sa_mask));
sigaddset(&mut sa.sa_mask as *mut libc::sigset_t, SIGALRM); sigaddset(addr_of_mut!(sa.sa_mask), SIGALRM);
sa.sa_flags = SA_NODEFER | SA_SIGINFO | SA_ONSTACK; sa.sa_flags = SA_NODEFER | SA_SIGINFO | SA_ONSTACK;
sa.sa_sigaction = handle_signal as usize; sa.sa_sigaction = handle_signal as usize;
let signals = handler.signals(); let signals = handler.signals();
@ -230,7 +230,7 @@ pub unsafe fn setup_signal_handler<T: 'static + 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")] #[cfg(feature = "std")]
{ {
let err_str = CString::new(format!("Failed to setup {} handler", sig)).unwrap(); let err_str = CString::new(format!("Failed to setup {} handler", sig)).unwrap();

View File

@ -6,6 +6,7 @@ use alloc::boxed::Box;
use core::{ use core::{
any::{Any, TypeId}, any::{Any, TypeId},
fmt::Debug, fmt::Debug,
ptr::addr_of,
}; };
// yolo // yolo
@ -18,7 +19,7 @@ use core::{
#[must_use] #[must_use]
pub fn pack_type_id(id: u64) -> TypeId { pub fn pack_type_id(id: u64) -> TypeId {
assert_eq_size!(TypeId, u64); 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` /// Unpack a `type_id` to an `u64`
@ -29,7 +30,7 @@ pub fn pack_type_id(id: u64) -> TypeId {
#[must_use] #[must_use]
pub fn unpack_type_id(id: TypeId) -> u64 { pub fn unpack_type_id(id: TypeId) -> u64 {
assert_eq_size!(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 /// A (de)serializable Any trait

View File

@ -215,16 +215,16 @@ pub trait ShMemProvider: Clone + Default + Debug {
fn new_map(&mut self, map_size: usize) -> Result<Self::Mem, Error>; fn new_map(&mut self, map_size: usize) -> Result<Self::Mem, Error>;
/// Get a mapping given its id and size /// Get a mapping given its id and size
fn from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result<Self::Mem, Error>; fn map_from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result<Self::Mem, Error>;
/// Get a mapping given a description /// Get a mapping given a description
fn from_description(&mut self, description: ShMemDescription) -> Result<Self::Mem, Error> { fn map_from_decription(&mut self, description: ShMemDescription) -> Result<Self::Mem, Error> {
self.from_id_and_size(description.id, description.size) self.map_from_id_and_size(description.id, description.size)
} }
/// Create a new sharedmap reference from an existing `id` and `len` /// Create a new sharedmap reference from an existing `id` and `len`
fn clone_ref(&mut self, mapping: &Self::Mem) -> Result<Self::Mem, Error> { fn clone_ref(&mut self, mapping: &Self::Mem) -> Result<Self::Mem, Error> {
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 /// 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<Self::Mem, Error> { fn existing_from_env(&mut self, env_name: &str) -> Result<Self::Mem, Error> {
let map_shm_str = env::var(env_name)?; let map_shm_str = env::var(env_name)?;
let map_size = str::parse::<usize>(&env::var(format!("{}_SIZE", env_name))?)?; let map_size = str::parse::<usize>(&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_shm_str,
map_size, map_size,
)) ))
@ -342,9 +342,9 @@ where
}) })
} }
fn from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result<Self::Mem, Error> { fn map_from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result<Self::Mem, Error> {
Ok(Self::Mem { 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(), provider: self.internal.clone(),
}) })
} }
@ -622,7 +622,7 @@ pub mod unix_shmem {
} }
} }
fn from_id_and_size(id: ShMemId, map_size: usize) -> Result<Self, Error> { fn map_from_id_and_size(id: ShMemId, map_size: usize) -> Result<Self, Error> {
unsafe { unsafe {
let shm_fd: i32 = id.to_string().parse().unwrap(); 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) MmapShMem::new(map_size, self.current_map_id)
} }
fn from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result<Self::Mem, Error> { fn map_from_id_and_size(
MmapShMem::from_id_and_size(id, size) &mut self,
id: ShMemId,
size: usize,
) -> Result<Self::Mem, Error> {
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 /// Get a [`UnixShMem`] of the existing shared memory mapping identified by id
pub fn from_id_and_size(id: ShMemId, map_size: usize) -> Result<Self, Error> { pub fn map_from_id_and_size(id: ShMemId, map_size: usize) -> Result<Self, Error> {
unsafe { unsafe {
let id_int: i32 = id.into(); let id_int: i32 = id.into();
let map = shmat(id_int, ptr::null(), 0) as *mut c_uchar; let map = shmat(id_int, ptr::null(), 0) as *mut c_uchar;
@ -843,8 +847,12 @@ pub mod unix_shmem {
CommonUnixShMem::new(map_size) CommonUnixShMem::new(map_size)
} }
fn from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result<Self::Mem, Error> { fn map_from_id_and_size(
CommonUnixShMem::from_id_and_size(id, size) &mut self,
id: ShMemId,
size: usize,
) -> Result<Self::Mem, Error> {
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. /// 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<Self, Error> { pub fn map_from_id_and_size(id: ShMemId, map_size: usize) -> Result<Self, Error> {
unsafe { unsafe {
let fd: i32 = id.to_string().parse().unwrap(); let fd: i32 = id.to_string().parse().unwrap();
#[allow(trivial_numeric_casts, clippy::cast_sign_loss)] #[allow(trivial_numeric_casts, clippy::cast_sign_loss)]
@ -1055,8 +1063,12 @@ pub mod unix_shmem {
Ok(mapping) Ok(mapping)
} }
fn from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result<Self::Mem, Error> { fn map_from_id_and_size(
AshmemShMem::from_id_and_size(id, size) &mut self,
id: ShMemId,
size: usize,
) -> Result<Self::Mem, Error> {
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<Self, Error> { fn map_from_id_and_size(id: ShMemId, map_size: usize) -> Result<Self, Error> {
unsafe { unsafe {
let map_str_bytes = id.id; let map_str_bytes = id.id;
// Unlike MapViewOfFile this one needs u32 // Unlike MapViewOfFile this one needs u32
@ -1228,8 +1240,8 @@ pub mod win32_shmem {
Win32ShMem::new_map(map_size) Win32ShMem::new_map(map_size)
} }
fn from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result<Self::Mem, Error> { fn map_from_id_and_size(&mut self, id: ShMemId, size: usize) -> Result<Self::Mem, Error> {
Win32ShMem::from_id_and_size(id, size) Win32ShMem::map_from_id_and_size(id, size)
} }
} }
} }

View File

@ -2,7 +2,10 @@
pub use tuple_list::{tuple_list, tuple_list_type, TupleList}; 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; use xxhash_rust::xxh3::xxh3_64;
@ -142,7 +145,7 @@ where
{ {
fn match_first_type<T: 'static>(&self) -> Option<&T> { fn match_first_type<T: 'static>(&self) -> Option<&T> {
if TypeId::of::<T>() == TypeId::of::<Head>() { if TypeId::of::<T>() == TypeId::of::<Head>() {
unsafe { (&self.0 as *const _ as *const T).as_ref() } unsafe { (addr_of!(self.0) as *const T).as_ref() }
} else { } else {
self.1.match_first_type::<T>() self.1.match_first_type::<T>()
} }
@ -150,7 +153,7 @@ where
fn match_first_type_mut<T: 'static>(&mut self) -> Option<&mut T> { fn match_first_type_mut<T: 'static>(&mut self) -> Option<&mut T> {
if TypeId::of::<T>() == TypeId::of::<Head>() { if TypeId::of::<T>() == TypeId::of::<Head>() {
unsafe { (&mut self.0 as *mut _ as *mut T).as_mut() } unsafe { (addr_of_mut!(self.0) as *mut T).as_mut() }
} else { } else {
self.1.match_first_type_mut::<T>() self.1.match_first_type_mut::<T>()
} }
@ -178,7 +181,7 @@ where
fn match_type<T: 'static>(&self, f: fn(t: &T)) { fn match_type<T: 'static>(&self, f: fn(t: &T)) {
// Switch this check to https://stackoverflow.com/a/60138532/7658998 when in stable and remove 'static // Switch this check to https://stackoverflow.com/a/60138532/7658998 when in stable and remove 'static
if TypeId::of::<T>() == TypeId::of::<Head>() { if TypeId::of::<T>() == TypeId::of::<Head>() {
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::<T>(f); self.1.match_type::<T>(f);
} }
@ -186,7 +189,7 @@ where
fn match_type_mut<T: 'static>(&mut self, f: fn(t: &mut T)) { fn match_type_mut<T: 'static>(&mut self, f: fn(t: &mut T)) {
// Switch this check to https://stackoverflow.com/a/60138532/7658998 when in stable and remove 'static // Switch this check to https://stackoverflow.com/a/60138532/7658998 when in stable and remove 'static
if TypeId::of::<T>() == TypeId::of::<Head>() { if TypeId::of::<T>() == TypeId::of::<Head>() {
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::<T>(f); self.1.match_type_mut::<T>(f);
} }
@ -251,7 +254,7 @@ where
{ {
fn match_name<T>(&self, name: &str) -> Option<&T> { fn match_name<T>(&self, name: &str) -> Option<&T> {
if type_eq::<Head, T>() && name == self.0.name() { if type_eq::<Head, T>() && 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 { } else {
self.1.match_name::<T>(name) self.1.match_name::<T>(name)
} }
@ -259,7 +262,7 @@ where
fn match_name_mut<T>(&mut self, name: &str) -> Option<&mut T> { fn match_name_mut<T>(&mut self, name: &str) -> Option<&mut T> {
if type_eq::<Head, T>() && name == self.0.name() { if type_eq::<Head, T>() && 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 { } else {
self.1.match_name_mut::<T>(name) self.1.match_name_mut::<T>(name)
} }
@ -291,7 +294,7 @@ where
fn match_name_type<T: 'static>(&self, name: &str) -> Option<&T> { fn match_name_type<T: 'static>(&self, name: &str) -> Option<&T> {
// Switch this check to https://stackoverflow.com/a/60138532/7658998 when in stable and remove 'static // Switch this check to https://stackoverflow.com/a/60138532/7658998 when in stable and remove 'static
if TypeId::of::<T>() == TypeId::of::<Head>() && name == self.0.name() { if TypeId::of::<T>() == TypeId::of::<Head>() && 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 { } else {
self.1.match_name_type::<T>(name) self.1.match_name_type::<T>(name)
} }
@ -300,7 +303,7 @@ where
fn match_name_type_mut<T: 'static>(&mut self, name: &str) -> Option<&mut T> { fn match_name_type_mut<T: 'static>(&mut self, name: &str) -> Option<&mut T> {
// Switch this check to https://stackoverflow.com/a/60138532/7658998 when in stable and remove 'static // Switch this check to https://stackoverflow.com/a/60138532/7658998 when in stable and remove 'static
if TypeId::of::<T>() == TypeId::of::<Head>() && name == self.0.name() { if TypeId::of::<T>() == TypeId::of::<Head>() && 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 { } else {
self.1.match_name_type_mut::<T>(name) self.1.match_name_type_mut::<T>(name)
} }

View File

@ -868,9 +868,9 @@ where
compiler_fence(Ordering::SeqCst); compiler_fence(Ordering::SeqCst);
#[allow(clippy::manual_assert)]
if !staterestorer.has_content() { if !staterestorer.has_content() {
#[cfg(unix)] #[cfg(unix)]
#[allow(clippy::manual_assert)]
if child_status == 137 { if child_status == 137 {
// Out of Memory, see https://tldp.org/LDP/abs/html/exitcodes.html // Out of Memory, see https://tldp.org/LDP/abs/html/exitcodes.html
// and https://github.com/AFLplusplus/LibAFL/issues/32 for discussion. // and https://github.com/AFLplusplus/LibAFL/issues/32 for discussion.

View File

@ -366,9 +366,9 @@ where
compiler_fence(Ordering::SeqCst); compiler_fence(Ordering::SeqCst);
#[allow(clippy::manual_assert)]
if !staterestorer.has_content() { if !staterestorer.has_content() {
#[cfg(unix)] #[cfg(unix)]
#[allow(clippy::manual_assert)]
if child_status == 137 { if child_status == 137 {
// Out of Memory, see https://tldp.org/LDP/abs/html/exitcodes.html // Out of Memory, see https://tldp.org/LDP/abs/html/exitcodes.html
// and https://github.com/AFLplusplus/LibAFL/issues/32 for discussion. // and https://github.com/AFLplusplus/LibAFL/issues/32 for discussion.

View File

@ -95,7 +95,6 @@ use crate::monitors::PerfFeature;
#[cfg(feature = "concolic_mutation")] #[cfg(feature = "concolic_mutation")]
#[allow(clippy::too_many_lines)] #[allow(clippy::too_many_lines)]
fn generate_mutations(iter: impl Iterator<Item = (SymExprRef, SymExpr)>) -> Vec<Vec<(usize, u8)>> { fn generate_mutations(iter: impl Iterator<Item = (SymExprRef, SymExpr)>) -> Vec<Vec<(usize, u8)>> {
use core::mem::size_of;
use hashbrown::HashMap; use hashbrown::HashMap;
use z3::{ use z3::{
ast::{Ast, Bool, Dynamic, BV}, ast::{Ast, Bool, Dynamic, BV},
@ -168,9 +167,7 @@ fn generate_mutations(iter: impl Iterator<Item = (SymExprRef, SymExpr)>) -> Vec<
Some(BV::from_u64(&ctx, value, u32::from(bits)).into()) Some(BV::from_u64(&ctx, value, u32::from(bits)).into())
} }
SymExpr::Integer128 { high: _, low: _ } => todo!(), SymExpr::Integer128 { high: _, low: _ } => todo!(),
SymExpr::NullPointer => { SymExpr::NullPointer => Some(BV::from_u64(&ctx, 0, usize::BITS).into()),
Some(BV::from_u64(&ctx, 0, (8 * size_of::<usize>()) as u32).into())
}
SymExpr::True => Some(Bool::from_bool(&ctx, true).into()), SymExpr::True => Some(Bool::from_bool(&ctx, true).into()),
SymExpr::False => Some(Bool::from_bool(&ctx, false).into()), SymExpr::False => Some(Bool::from_bool(&ctx, false).into()),
SymExpr::Bool { value } => Some(Bool::from_bool(&ctx, value).into()), SymExpr::Bool { value } => Some(Bool::from_bool(&ctx, value).into()),

View File

@ -63,7 +63,7 @@ pub struct ClangWrapper {
need_libafl_arg: bool, need_libafl_arg: bool,
has_libafl_arg: bool, has_libafl_arg: bool,
from_args_called: bool, parse_args_called: bool,
base_args: Vec<String>, base_args: Vec<String>,
cc_args: Vec<String>, cc_args: Vec<String>,
link_args: Vec<String>, link_args: Vec<String>,
@ -72,7 +72,7 @@ pub struct ClangWrapper {
#[allow(clippy::match_same_arms)] // for the linking = false wip for "shared" #[allow(clippy::match_same_arms)] // for the linking = false wip for "shared"
impl CompilerWrapper for ClangWrapper { impl CompilerWrapper for ClangWrapper {
fn from_args<S>(&mut self, args: &[S]) -> Result<&'_ mut Self, Error> fn parse_args<S>(&mut self, args: &[S]) -> Result<&'_ mut Self, Error>
where where
S: AsRef<str>, S: AsRef<str>,
{ {
@ -83,13 +83,13 @@ impl CompilerWrapper for ClangWrapper {
)); ));
} }
if self.from_args_called { if self.parse_args_called {
return Err(Error::Unknown( 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(), .to_string(),
)); ));
} }
self.from_args_called = true; self.parse_args_called = true;
if args.len() == 1 { if args.len() == 1 {
return Err(Error::InvalidArguments( return Err(Error::InvalidArguments(
@ -283,7 +283,7 @@ impl ClangWrapper {
bit_mode: 0, bit_mode: 0,
need_libafl_arg: false, need_libafl_arg: false,
has_libafl_arg: false, has_libafl_arg: false,
from_args_called: false, parse_args_called: false,
base_args: vec![], base_args: vec![],
cc_args: vec![], cc_args: vec![],
link_args: vec![], link_args: vec![],
@ -342,7 +342,7 @@ mod tests {
#[test] #[test]
fn test_clang_version() { fn test_clang_version() {
if let Err(res) = ClangWrapper::new() if let Err(res) = ClangWrapper::new()
.from_args(&["my-clang", "-v"]) .parse_args(&["my-clang", "-v"])
.unwrap() .unwrap()
.run() .run()
{ {

View File

@ -90,7 +90,7 @@ pub const LIB_PREFIX: &str = "lib";
/// Wrap a compiler hijacking its arguments /// Wrap a compiler hijacking its arguments
pub trait CompilerWrapper { pub trait CompilerWrapper {
/// Set the wrapper arguments parsing a command line set of arguments /// Set the wrapper arguments parsing a command line set of arguments
fn from_args<S>(&mut self, args: &[S]) -> Result<&'_ mut Self, Error> fn parse_args<S>(&mut self, args: &[S]) -> Result<&'_ mut Self, Error>
where where
S: AsRef<str>; S: AsRef<str>;

View File

@ -7,7 +7,10 @@ this helps finding mem errors early.
*/ */
use backtrace::Backtrace; 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 frida_gum::{ModuleDetails, NativePointer, RangeDetails};
use hashbrown::HashMap; use hashbrown::HashMap;
use nix::sys::mman::{mmap, MapFlags, ProtFlags}; use nix::sys::mman::{mmap, MapFlags, ProtFlags};
@ -362,7 +365,7 @@ impl AsanRuntime {
rlim_cur: 0, rlim_cur: 0,
rlim_max: 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 stack_rlimit.rlim_cur as usize
} }
@ -387,7 +390,7 @@ impl AsanRuntime {
#[must_use] #[must_use]
pub fn current_stack() -> (usize, usize) { pub fn current_stack() -> (usize, usize) {
let mut stack_var = 0xeadbeef; 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(); let range_details = RangeDetails::with_address(stack_address as u64).unwrap();
// Write something to (hopefully) make sure the val isn't optimized out // Write something to (hopefully) make sure the val isn't optimized out
unsafe { unsafe {
@ -1853,7 +1856,7 @@ impl AsanRuntime {
; self_addr: ; self_addr:
; .qword self as *mut _ as *mut c_void as i64 ; .qword self as *mut _ as *mut c_void as i64
; self_regs_addr: ; 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: ; trap_func:
; .qword AsanRuntime::handle_trap as *mut c_void as i64 ; .qword AsanRuntime::handle_trap as *mut c_void as i64
); );

View File

@ -1,6 +1,6 @@
//! Functionality regarding binary-only coverage collection. //! Functionality regarding binary-only coverage collection.
use core::ptr::addr_of_mut;
use dynasmrt::{dynasm, DynasmApi, DynasmLabelApi}; use dynasmrt::{dynasm, DynasmApi, DynasmLabelApi};
use std::ffi::c_void;
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
use frida_gum::instruction_writer::X86Register; use frida_gum::instruction_writer::X86Register;
@ -116,7 +116,7 @@ impl CoverageRuntime {
; popfq ; popfq
; ret ; ret
;map_addr: ;map_addr:
;.qword &mut self.map as *mut _ as *mut c_void as i64 ;.qword addr_of_mut!(self.map) as i64
;previous_loc: ;previous_loc:
;.qword 0 ;.qword 0
); );
@ -152,7 +152,7 @@ impl CoverageRuntime {
self.current_log_impl = writer.pc(); self.current_log_impl = writer.pc();
writer.put_bytes(self.blob_maybe_log()); 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()); writer.put_bytes(&prev_loc_pointer.to_ne_bytes());

View File

@ -2,6 +2,7 @@
//! writing basic-block trace files to be read by coverage analysis tools, such as [Lighthouse](https://github.com/gaasedelen/lighthouse), //! 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. //! [bncov](https://github.com/ForAllSecure/bncov), [dragondance](https://github.com/0ffffffffh/dragondance), etc.
use core::ptr::addr_of;
use libafl::Error; use libafl::Error;
use rangemap::RangeMap; use rangemap::RangeMap;
use std::{ use std::{
@ -97,7 +98,7 @@ impl<'a> DrCovWriter<'a> {
}; };
writer writer
.write_all(unsafe { .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(); .unwrap();
} }

View File

@ -23,10 +23,8 @@ pub fn libfuzzer_initialize(args: &[String]) -> i32 {
#[allow(clippy::cast_possible_wrap)] #[allow(clippy::cast_possible_wrap)]
let argc = argv.len() as i32; let argc = argv.len() as i32;
unsafe { unsafe {
libafl_targets_libfuzzer_init( let argv_ptr = argv.as_ptr();
&argc as *const i32, libafl_targets_libfuzzer_init(core::ptr::addr_of!(argc), core::ptr::addr_of!(argv_ptr))
&argv.as_ptr() as *const *const *const u8,
)
} }
} }