more clippy fixes

This commit is contained in:
Dominik Maier 2021-03-02 19:57:43 +01:00
parent dbd3cbd99c
commit c7f1d83b6e
21 changed files with 70 additions and 66 deletions

View File

@ -120,8 +120,8 @@ unsafe fn shmem2page<SH: ShMem>(afl_shmem: &SH) -> *const LlmpPage {
#[inline] #[inline]
unsafe fn llmp_msg_in_page(page: *const LlmpPage, msg: *const LlmpMsg) -> bool { unsafe fn llmp_msg_in_page(page: *const LlmpPage, msg: *const LlmpMsg) -> bool {
/* DBG("llmp_msg_in_page %p within %p-%p\n", msg, page, page + page->size_total); */ /* DBG("llmp_msg_in_page %p within %p-%p\n", msg, page, page + page->size_total); */
return (page as *const u8) < msg as *const u8 (page as *const u8) < msg as *const u8
&& (page as *const u8).offset((*page).size_total as isize) > msg as *const u8; && (page as *const u8).add((*page).size_total) > msg as *const u8
} }
/// allign to LLMP_PREF_ALIGNNMENT=64 bytes /// allign to LLMP_PREF_ALIGNNMENT=64 bytes
@ -198,9 +198,9 @@ unsafe fn llmp_next_msg_ptr_checked<SH: ShMem>(
) -> Result<*mut LlmpMsg, Error> { ) -> Result<*mut LlmpMsg, Error> {
let page = map.page_mut(); let page = map.page_mut();
let map_size = map.shmem.map().len(); let map_size = map.shmem.map().len();
let msg_begin_min = (page as *const u8).offset(size_of::<LlmpPage>() as isize); let msg_begin_min = (page as *const u8).add(size_of::<LlmpPage>());
// We still need space for this msg (alloc_size). // We still need space for this msg (alloc_size).
let msg_begin_max = (page as *const u8).offset((map_size - alloc_size) as isize); let msg_begin_max = (page as *const u8).add(map_size - alloc_size);
let next = _llmp_next_msg_ptr(last_msg); let next = _llmp_next_msg_ptr(last_msg);
let next_ptr = next as *const u8; let next_ptr = next as *const u8;
if next_ptr >= msg_begin_min && next_ptr <= msg_begin_max { if next_ptr >= msg_begin_min && next_ptr <= msg_begin_max {
@ -217,9 +217,9 @@ unsafe fn llmp_next_msg_ptr_checked<SH: ShMem>(
#[inline] #[inline]
unsafe fn _llmp_next_msg_ptr(last_msg: *const LlmpMsg) -> *mut LlmpMsg { unsafe fn _llmp_next_msg_ptr(last_msg: *const LlmpMsg) -> *mut LlmpMsg {
/* DBG("_llmp_next_msg_ptr %p %lu + %lu\n", last_msg, last_msg->buf_len_padded, sizeof(llmp_message)); */ /* DBG("_llmp_next_msg_ptr %p %lu + %lu\n", last_msg, last_msg->buf_len_padded, sizeof(llmp_message)); */
return (last_msg as *mut u8) (last_msg as *mut u8)
.offset(size_of::<LlmpMsg>() as isize) .add(size_of::<LlmpMsg>())
.offset((*last_msg).buf_len_padded as isize) as *mut LlmpMsg; .add((*last_msg).buf_len_padded as usize) as *mut LlmpMsg
} }
/// Description of a shared map. /// Description of a shared map.
@ -262,6 +262,7 @@ pub struct LlmpMsg {
/// The message we receive /// The message we receive
impl LlmpMsg { impl LlmpMsg {
/// Gets the buffer from this message as slice, with the corrent length. /// Gets the buffer from this message as slice, with the corrent length.
/// # Safety
/// This is unsafe if somebody has access to shared mem pages on the system. /// This is unsafe if somebody has access to shared mem pages on the system.
pub unsafe fn as_slice_unsafe(&self) -> &[u8] { pub unsafe fn as_slice_unsafe(&self) -> &[u8] {
slice::from_raw_parts(self.buf.as_ptr(), self.buf_len as usize) slice::from_raw_parts(self.buf.as_ptr(), self.buf_len as usize)
@ -285,14 +286,13 @@ impl LlmpMsg {
unsafe { unsafe {
let map_size = map.shmem.map().len(); let map_size = map.shmem.map().len();
let buf_ptr = self.buf.as_ptr(); let buf_ptr = self.buf.as_ptr();
if buf_ptr > (map.page_mut() as *const u8).offset(size_of::<LlmpPage>() as isize) if buf_ptr > (map.page_mut() as *const u8).add(size_of::<LlmpPage>())
&& buf_ptr && buf_ptr
<= (map.page_mut() as *const u8) <= (map.page_mut() as *const u8).add(map_size - size_of::<LlmpMsg>() as usize)
.offset((map_size - size_of::<LlmpMsg>() as usize) as isize)
{ {
// The message header is in the page. Continue with checking the body. // The message header is in the page. Continue with checking the body.
let len = self.buf_len_padded as usize + size_of::<LlmpMsg>(); let len = self.buf_len_padded as usize + size_of::<LlmpMsg>();
buf_ptr <= (map.page_mut() as *const u8).offset((map_size - len) as isize) buf_ptr <= (map.page_mut() as *const u8).add(map_size - len)
} else { } else {
false false
} }
@ -448,6 +448,8 @@ where
/// Completely reset the current sender map. /// Completely reset the current sender map.
/// Afterwards, no receiver should read from it at a different location. /// Afterwards, no receiver should read from it at a different location.
/// This is only useful if all connected llmp parties start over, for example after a crash. /// This is only useful if all connected llmp parties start over, for example after a crash.
/// # Safety
/// Only safe if you really really restart the page on everything connected
pub unsafe fn reset(&mut self) { pub unsafe fn reset(&mut self) {
_llmp_page_init(&mut self.out_maps.last_mut().unwrap().shmem, self.id, true); _llmp_page_init(&mut self.out_maps.last_mut().unwrap().shmem, self.id, true);
self.last_msg_sent = ptr::null_mut(); self.last_msg_sent = ptr::null_mut();
@ -640,7 +642,7 @@ where
panic!("Allocated new message without calling send() inbetween. ret: {:?}, page: {:?}, complete_msg_size: {:?}, size_used: {:?}, last_msg: {:?}", ret, page, panic!("Allocated new message without calling send() inbetween. ret: {:?}, page: {:?}, complete_msg_size: {:?}, size_used: {:?}, last_msg: {:?}", ret, page,
buf_len_padded, (*page).size_used, last_msg); buf_len_padded, (*page).size_used, last_msg);
} }
(*page).size_used = (*page).size_used + complete_msg_size; (*page).size_used += complete_msg_size;
(*ret).buf_len_padded = buf_len_padded as u64; (*ret).buf_len_padded = buf_len_padded as u64;
(*ret).buf_len = buf_len as u64; (*ret).buf_len = buf_len as u64;
/* DBG("Returning new message at %p with len %ld, TAG was %x", ret, ret->buf_len_padded, ret->tag); */ /* DBG("Returning new message at %p with len %ld, TAG was %x", ret, ret->buf_len_padded, ret->tag); */
@ -714,16 +716,17 @@ where
} }
/// Allocates the next space on this sender page /// Allocates the next space on this sender page
pub unsafe fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, Error> { pub fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, Error> {
match self.alloc_next_if_space(buf_len) { if let Some(msg) = unsafe { self.alloc_next_if_space(buf_len) } {
Some(msg) => return Ok(msg), return Ok(msg);
_ => (),
}; };
/* no more space left! We'll have to start a new page */ /* no more space left! We'll have to start a new page */
self.handle_out_eop()?; unsafe {
self.handle_out_eop()?;
}
match self.alloc_next_if_space(buf_len) { match unsafe { self.alloc_next_if_space(buf_len) } {
Some(msg) => Ok(msg), Some(msg) => Ok(msg),
None => Err(Error::Unknown(format!( None => Err(Error::Unknown(format!(
"Error allocating {} bytes in shmap", "Error allocating {} bytes in shmap",
@ -733,6 +736,8 @@ where
} }
/// Cancel send of the next message, this allows us to allocate a new message without sending this one. /// Cancel send of the next message, this allows us to allocate a new message without sending this one.
/// # Safety
/// They msg pointer may no longer be used after `cancel_send`
pub unsafe fn cancel_send(&mut self, msg: *mut LlmpMsg) { pub unsafe fn cancel_send(&mut self, msg: *mut LlmpMsg) {
/* DBG("Client %d cancels send of msg at %p with tag 0x%X and size %ld", client->id, msg, msg->tag, /* DBG("Client %d cancels send of msg at %p with tag 0x%X and size %ld", client->id, msg, msg->tag,
* msg->buf_len_padded); */ * msg->buf_len_padded); */
@ -1047,11 +1052,15 @@ where
} }
/// Get the unsafe ptr to this page, situated on the shared map /// Get the unsafe ptr to this page, situated on the shared map
/// # Safety
/// The unsafe page pointer is obviously unsafe.
pub unsafe fn page_mut(&mut self) -> *mut LlmpPage { pub unsafe fn page_mut(&mut self) -> *mut LlmpPage {
shmem2page_mut(&mut self.shmem) shmem2page_mut(&mut self.shmem)
} }
/// Get the unsafe ptr to this page, situated on the shared map /// Get the unsafe ptr to this page, situated on the shared map
/// # Safety
/// The unsafe page pointer is obviously unsafe.
pub unsafe fn page(&self) -> *const LlmpPage { pub unsafe fn page(&self) -> *const LlmpPage {
shmem2page(&self.shmem) shmem2page(&self.shmem)
} }
@ -1250,7 +1259,7 @@ where
let listener = TcpListener::bind(format!("127.0.0.1:{}", port))?; let listener = TcpListener::bind(format!("127.0.0.1:{}", port))?;
// accept connections and process them, spawning a new thread for each one // accept connections and process them, spawning a new thread for each one
println!("Server listening on port {}", port); println!("Server listening on port {}", port);
return self.launch_tcp_listener(listener); self.launch_tcp_listener(listener)
} }
#[cfg(feature = "std")] #[cfg(feature = "std")]

View File

@ -105,7 +105,7 @@ macro_rules! create_serde_registry_for_trait {
.get(&id) .get(&id)
.expect("Cannot deserialize an unregistered type") .expect("Cannot deserialize an unregistered type")
}; };
let seed = DeserializeCallbackSeed::<dyn $trait_name> { cb: cb }; let seed = DeserializeCallbackSeed::<dyn $trait_name> { cb };
let obj: Self::Value = visitor.next_element_seed(seed)?.unwrap(); let obj: Self::Value = visitor.next_element_seed(seed)?.unwrap();
Ok(obj) Ok(obj)
} }

View File

@ -3,11 +3,11 @@
#[cfg(feature = "std")] #[cfg(feature = "std")]
#[cfg(unix)] #[cfg(unix)]
pub use shmem::UnixShMem; pub use unix_shmem::UnixShMem;
#[cfg(feature = "std")] #[cfg(feature = "std")]
#[cfg(windows)] #[cfg(windows)]
pub use shmem::Win32ShMem; pub use unix_shmem::Win32ShMem;
use alloc::string::{String, ToString}; use alloc::string::{String, ToString};
use core::fmt::Debug; use core::fmt::Debug;
@ -101,7 +101,7 @@ pub trait ShMem: Sized + Debug {
#[cfg(unix)] #[cfg(unix)]
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub mod shmem { pub mod unix_shmem {
use core::{mem::size_of, ptr, slice}; use core::{mem::size_of, ptr, slice};
use libc::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_ushort, c_void}; use libc::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_ushort, c_void};
@ -288,7 +288,7 @@ pub mod shmem {
(*shm).shm_str[0 as c_int as usize] = 0u8; (*shm).shm_str[0 as c_int as usize] = 0u8;
return ptr::null_mut(); return ptr::null_mut();
} }
return (*shm).map; (*shm).map
} }
/// Uses a shmap id string to open a shared map /// Uses a shmap id string to open a shared map
@ -319,7 +319,7 @@ pub mod shmem {
(*shm).shm_str[0] = 0u8; (*shm).shm_str[0] = 0u8;
return ptr::null_mut(); return ptr::null_mut();
} }
return (*shm).map; (*shm).map
} }
} }

View File

@ -68,12 +68,8 @@ pub trait MatchType {
} }
impl MatchType for () { impl MatchType for () {
fn match_type<T: 'static>(&self, _f: fn(t: &T)) { fn match_type<T: 'static>(&self, _f: fn(t: &T)) {}
() 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)) {
()
}
} }
impl<Head, Tail> MatchType for (Head, Tail) impl<Head, Tail> MatchType for (Head, Tail)
@ -182,7 +178,7 @@ where
fn append(self, value: T) -> Self::AppendResult { fn append(self, value: T) -> Self::AppendResult {
let (head, tail) = self; let (head, tail) = self;
return (head, tail.append(value)); (head, tail.append(value))
} }
} }

View File

@ -214,7 +214,7 @@ where
pub fn new(base: CS) -> Self { pub fn new(base: CS) -> Self {
Self { Self {
base: base, base,
skip_not_fav_prob: DEFAULT_SKIP_NOT_FAV_PROB, skip_not_fav_prob: DEFAULT_SKIP_NOT_FAV_PROB,
phantom: PhantomData, phantom: PhantomData,
} }
@ -222,8 +222,8 @@ where
pub fn with_skip_prob(base: CS, skip_not_fav_prob: u64) -> Self { pub fn with_skip_prob(base: CS, skip_not_fav_prob: u64) -> Self {
Self { Self {
base: base, base,
skip_not_fav_prob: skip_not_fav_prob, skip_not_fav_prob,
phantom: PhantomData, phantom: PhantomData,
} }
} }

View File

@ -98,7 +98,7 @@ where
Ok(Self { Ok(Self {
entries: vec![], entries: vec![],
current: None, current: None,
dir_path: dir_path, dir_path,
}) })
} }
} }

View File

@ -183,7 +183,7 @@ where
Testcase { Testcase {
input: Some(input), input: Some(input),
filename: None, filename: None,
fitness: fitness, fitness,
metadata: SerdeAnyMap::new(), metadata: SerdeAnyMap::new(),
exec_time: None, exec_time: None,
cached_len: None, cached_len: None,

View File

@ -280,14 +280,13 @@ where
let observers: OT = postcard::from_bytes(&observers_buf)?; let observers: OT = postcard::from_bytes(&observers_buf)?;
// TODO include ExitKind in NewTestcase // TODO include ExitKind in NewTestcase
let fitness = state.is_interesting(&input, &observers, ExitKind::Ok)?; let fitness = state.is_interesting(&input, &observers, ExitKind::Ok)?;
if fitness > 0 { if fitness > 0
if state && state
.add_if_interesting(&input, fitness, scheduler)? .add_if_interesting(&input, fitness, scheduler)?
.is_some() .is_some()
{ {
#[cfg(feature = "std")] #[cfg(feature = "std")]
println!("Added received Testcase"); println!("Added received Testcase");
}
} }
Ok(()) Ok(())
} }

View File

@ -66,7 +66,7 @@ where
{ {
pub fn new(stats: ST) -> Self { pub fn new(stats: ST) -> Self {
Self { Self {
stats: stats, stats,
events: vec![], events: vec![],
phantom: PhantomData, phantom: PhantomData,
} }

View File

@ -323,7 +323,7 @@ where
/// The map can be shared. /// The map can be shared.
pub fn with_history_map(name: &'static str, history_map: Vec<T>) -> Self { pub fn with_history_map(name: &'static str, history_map: Vec<T>) -> Self {
Self { Self {
history_map: history_map, history_map,
name: name.to_string(), name: name.to_string(),
indexes: None, indexes: None,
novelties: None, novelties: None,

View File

@ -142,8 +142,8 @@ where
{ {
pub fn new(scheduler: CS, stages: ST) -> Self { pub fn new(scheduler: CS, stages: ST) -> Self {
Self { Self {
scheduler: scheduler, scheduler,
stages: stages, stages,
phantom: PhantomData, phantom: PhantomData,
} }
} }

View File

@ -61,7 +61,7 @@ where
{ {
pub fn new(max_size: usize) -> Self { pub fn new(max_size: usize) -> Self {
Self { Self {
max_size: max_size, max_size,
phantom: PhantomData, phantom: PhantomData,
} }
} }
@ -103,7 +103,7 @@ where
{ {
pub fn new(max_size: usize) -> Self { pub fn new(max_size: usize) -> Self {
Self { Self {
max_size: max_size, max_size,
phantom: PhantomData, phantom: PhantomData,
} }
} }

View File

@ -64,7 +64,7 @@ impl From<&[u8]> for BytesInput {
impl BytesInput { impl BytesInput {
/// Creates a new bytes input using the given bytes /// Creates a new bytes input using the given bytes
pub fn new(bytes: Vec<u8>) -> Self { pub fn new(bytes: Vec<u8>) -> Self {
Self { bytes: bytes } Self { bytes }
} }
} }

View File

@ -767,7 +767,7 @@ fn from_hex(hex: u8) -> Result<u8, Error> {
if hex >= 97 && hex <= 102 { if hex >= 97 && hex <= 102 {
return Ok(hex - 87); return Ok(hex - 87);
} }
return Err(Error::IllegalArgument("".to_owned())); Err(Error::IllegalArgument("".to_owned()))
} }
/// Decodes a dictionary token: 'foo\x41\\and\"bar' -> 'fooA\and"bar' /// Decodes a dictionary token: 'foo\x41\\and\"bar' -> 'fooA\and"bar'
@ -801,7 +801,7 @@ pub fn str_decode(item: &str) -> Result<Vec<u8>, Error> {
} }
} }
return Ok(token); Ok(token)
} }
#[cfg(test)] #[cfg(test)]

View File

@ -133,7 +133,7 @@ where
/// Create a new StdScheduledMutator instance specifying mutations /// Create a new StdScheduledMutator instance specifying mutations
pub fn with_mutations(mutations: Vec<MutationFunction<I, S>>) -> Self { pub fn with_mutations(mutations: Vec<MutationFunction<I, S>>) -> Self {
StdScheduledMutator { StdScheduledMutator {
mutations: mutations, mutations,
phantom: PhantomData, phantom: PhantomData,
} }
} }
@ -202,7 +202,7 @@ where
scheduled.add_mutation(mutation_bitflip); scheduled.add_mutation(mutation_bitflip);
scheduled.add_mutation(mutation_splice); scheduled.add_mutation(mutation_splice);
Self { Self {
scheduled: scheduled, scheduled,
phantom: PhantomData, phantom: PhantomData,
} }
} }
@ -253,7 +253,7 @@ where
//scheduled.add_mutation(mutation_splice); //scheduled.add_mutation(mutation_splice);
HavocBytesMutator { HavocBytesMutator {
scheduled: scheduled, scheduled,
phantom: PhantomData, phantom: PhantomData,
} }
} }

View File

@ -54,7 +54,7 @@ impl Tokens {
return false; return false;
} }
self.token_vec.push(token.to_vec()); self.token_vec.push(token.to_vec());
return true; true
} }
/// Reads a tokens file, returning the count of new entries read /// Reads a tokens file, returning the count of new entries read
@ -117,7 +117,7 @@ impl Tokens {
/// Gets the tokens stored in this db /// Gets the tokens stored in this db
pub fn tokens(&self) -> &[Vec<u8>] { pub fn tokens(&self) -> &[Vec<u8>] {
return &self.token_vec; &self.token_vec
} }
} }

View File

@ -339,6 +339,6 @@ where
{ {
/// Creates a new MapObserver /// Creates a new MapObserver
pub fn new(base: M) -> Self { pub fn new(base: M) -> Self {
Self { base: base } Self { base }
} }
} }

View File

@ -157,7 +157,7 @@ where
/// Creates a new default mutational stage /// Creates a new default mutational stage
pub fn new(mutator: M) -> Self { pub fn new(mutator: M) -> Self {
Self { Self {
mutator: mutator, mutator,
phantom: PhantomData, phantom: PhantomData,
} }
} }

View File

@ -523,7 +523,7 @@ where
manager.fire( manager.fire(
self, self,
Event::NewTestcase { Event::NewTestcase {
input: input, input,
observers_buf, observers_buf,
corpus_size: self.corpus().count() + 1, corpus_size: self.corpus().count() + 1,
client_config: "TODO".into(), client_config: "TODO".into(),

View File

@ -187,7 +187,7 @@ where
{ {
pub fn new(print_fn: F) -> Self { pub fn new(print_fn: F) -> Self {
Self { Self {
print_fn: print_fn, print_fn,
start_time: current_time(), start_time: current_time(),
corpus_size: 0, corpus_size: 0,
client_stats: vec![], client_stats: vec![],
@ -196,8 +196,8 @@ where
pub fn with_time(print_fn: F, start_time: time::Duration) -> Self { pub fn with_time(print_fn: F, start_time: time::Duration) -> Self {
Self { Self {
print_fn: print_fn, print_fn,
start_time: start_time, start_time,
corpus_size: 0, corpus_size: 0,
client_stats: vec![], client_stats: vec![],
} }

View File

@ -204,7 +204,7 @@ impl Rand for Xoshiro256StarRand {
self.rand_seed[3] = self.rand_seed[3].rotate_left(45); self.rand_seed[3] = self.rand_seed[3].rotate_left(45);
return ret; ret
} }
} }
@ -235,7 +235,7 @@ impl Rand for XorShift64Rand {
x ^= x >> 7; x ^= x >> 7;
x ^= x << 17; x ^= x << 17;
self.rand_seed = x; self.rand_seed = x;
return x; x
} }
} }
@ -262,7 +262,7 @@ impl Rand for Lehmer64Rand {
#[inline] #[inline]
fn next(&mut self) -> u64 { fn next(&mut self) -> u64 {
self.rand_seed *= 0xda942042e4dd58b5; self.rand_seed *= 0xda942042e4dd58b5;
return (self.rand_seed >> 64) as u64; (self.rand_seed >> 64) as u64
} }
} }