From 8059a765ed18bb20fbfa0afcdac88cfbd1cce63f Mon Sep 17 00:00:00 2001 From: Andrea Fioraldi Date: Mon, 15 Feb 2021 14:10:54 +0100 Subject: [PATCH] AflError -> Error & AflShmem -> UnixShMem --- afl/examples/llmp_test/main.rs | 12 +-- afl/src/bolts/llmp.rs | 148 ++++++++++++++-------------- afl/src/bolts/serdeany.rs | 10 +- afl/src/bolts/shmem.rs | 54 +++++----- afl/src/corpus/inmemory.rs | 6 +- afl/src/corpus/mod.rs | 12 +-- afl/src/corpus/ondisk.rs | 6 +- afl/src/corpus/queue.rs | 8 +- afl/src/corpus/testcase.rs | 6 +- afl/src/events/llmp.rs | 46 ++++----- afl/src/events/logger.rs | 12 +-- afl/src/events/mod.rs | 22 ++--- afl/src/executors/inprocess.rs | 8 +- afl/src/executors/mod.rs | 16 +-- afl/src/feedbacks/map.rs | 10 +- afl/src/feedbacks/mod.rs | 40 ++++---- afl/src/generators/mod.rs | 8 +- afl/src/inputs/mod.rs | 14 +-- afl/src/lib.rs | 18 ++-- afl/src/mutators/mod.rs | 6 +- afl/src/mutators/mutations.rs | 68 ++++++------- afl/src/mutators/scheduled.rs | 8 +- afl/src/mutators/token_mutations.rs | 6 +- afl/src/observers/map.rs | 12 +-- afl/src/observers/mod.rs | 32 +++--- afl/src/stages/mod.rs | 10 +- afl/src/stages/mutational.rs | 6 +- afl/src/state/mod.rs | 24 ++--- fuzzers/libfuzzer_dummy/src/mod.rs | 8 +- fuzzers/libfuzzer_libpng/src/mod.rs | 8 +- 30 files changed, 322 insertions(+), 322 deletions(-) diff --git a/afl/examples/llmp_test/main.rs b/afl/examples/llmp_test/main.rs index 4f8f79abda..ce7b36d546 100644 --- a/afl/examples/llmp_test/main.rs +++ b/afl/examples/llmp_test/main.rs @@ -7,15 +7,15 @@ use core::{convert::TryInto, time::Duration}; use std::{thread, time}; use afl::{ - bolts::{llmp, shmem::AflShmem}, - AflError, + bolts::{llmp, shmem::UnixShMem}, + Error, }; const TAG_SIMPLE_U32_V1: u32 = 0x51300321; const TAG_MATH_RESULT_V1: u32 = 0x77474331; fn adder_loop(port: u16) -> ! { - let mut client = llmp::LlmpClient::::create_attach_to_tcp(port).unwrap(); + let mut client = llmp::LlmpClient::::create_attach_to_tcp(port).unwrap(); let mut last_result: u32 = 0; let mut current_result: u32 = 0; loop { @@ -55,7 +55,7 @@ fn broker_message_hook( client_id: u32, tag: llmp::Tag, message: &[u8], -) -> Result { +) -> Result { match tag { TAG_SIMPLE_U32_V1 => { println!( @@ -94,7 +94,7 @@ fn main() { match mode.as_str() { "broker" => { - let mut broker = llmp::LlmpBroker::::new().unwrap(); + let mut broker = llmp::LlmpBroker::::new().unwrap(); broker .launch_tcp_listener( std::net::TcpListener::bind(format!("127.0.0.1:{}", port)).unwrap(), @@ -103,7 +103,7 @@ fn main() { broker.loop_forever(&mut broker_message_hook, Some(Duration::from_millis(5))) } "ctr" => { - let mut client = llmp::LlmpClient::::create_attach_to_tcp(port).unwrap(); + let mut client = llmp::LlmpClient::::create_attach_to_tcp(port).unwrap(); let mut counter: u32 = 0; loop { counter = counter.wrapping_add(1); diff --git a/afl/src/bolts/llmp.rs b/afl/src/bolts/llmp.rs index 48737fca73..b3b6f5029f 100644 --- a/afl/src/bolts/llmp.rs +++ b/afl/src/bolts/llmp.rs @@ -67,7 +67,7 @@ use std::{ }; use super::shmem::{ShMem, ShMemDescription}; -use crate::AflError; +use crate::Error; /// We'll start off with 256 megabyte maps per fuzzer client const LLMP_PREF_INITIAL_MAP_SIZE: usize = 1 << 28; @@ -140,7 +140,7 @@ const fn llmp_align(to_align: usize) -> usize { /// If the content of the env is _NULL, returns None #[cfg(feature = "std")] #[inline] -fn msg_offset_from_env(env_name: &str) -> Result, AflError> { +fn msg_offset_from_env(env_name: &str) -> Result, Error> { let msg_offset_str = env::var(&format!("{}_OFFSET", env_name))?; Ok(if msg_offset_str == _NULL_ENV_STR { None @@ -191,7 +191,7 @@ unsafe fn llmp_next_msg_ptr_checked( map: &mut LlmpSharedMap, last_msg: *const LlmpMsg, alloc_size: usize, -) -> Result<*mut LlmpMsg, AflError> { +) -> Result<*mut LlmpMsg, Error> { let page = map.page_mut(); let map_size = map.shmem.map().len(); let msg_begin_min = (page as *const u8).offset(size_of::() as isize); @@ -202,7 +202,7 @@ unsafe fn llmp_next_msg_ptr_checked( if next_ptr >= msg_begin_min && next_ptr <= msg_begin_max { Ok(next) } else { - Err(AflError::IllegalState(format!( + Err(Error::IllegalState(format!( "Inconsistent data on sharedmap, or Bug (next_ptr was {:x}, sharedmap page was {:x})", next_ptr as usize, page as usize ))) @@ -265,12 +265,12 @@ impl LlmpMsg { /// Gets the buffer from this message as slice, with the corrent length. #[inline] - pub fn as_slice(&self, map: &mut LlmpSharedMap) -> Result<&[u8], AflError> { + pub fn as_slice(&self, map: &mut LlmpSharedMap) -> Result<&[u8], Error> { unsafe { if self.in_map(map) { Ok(self.as_slice_unsafe()) } else { - Err(AflError::IllegalState("Current message not in page. The sharedmap get tampered with or we have a BUG.".into())) + Err(Error::IllegalState("Current message not in page. The sharedmap get tampered with or we have a BUG.".into())) } } } @@ -314,7 +314,7 @@ where { #[cfg(feature = "std")] /// Creates either a broker, if the tcp port is not bound, or a client, connected to this port. - pub fn on_port(port: u16) -> Result { + pub fn on_port(port: u16) -> Result { match TcpListener::bind(format!("127.0.0.1:{}", port)) { Ok(listener) => { // We got the port. We are the broker! :) @@ -332,14 +332,14 @@ where client: LlmpClient::create_attach_to_tcp(port)?, }) } - _ => Err(AflError::File(e)), + _ => Err(Error::File(e)), } } } } /// Describe this in a reproducable fashion, if it's a client - pub fn describe(&self) -> Result { + pub fn describe(&self) -> Result { Ok(match self { LlmpConnection::IsClient { client } => client.describe()?, _ => todo!("Only client can be described atm."), @@ -349,14 +349,14 @@ where /// Recreate an existing client from the stored description pub fn existing_client_from_description( description: &LlmpClientDescription, - ) -> Result, AflError> { + ) -> Result, Error> { Ok(LlmpConnection::IsClient { client: LlmpClient::existing_client_from_description(description)?, }) } /// Sends the given buffer over this connection, no matter if client or broker. - pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), AflError> { + pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), Error> { match self { LlmpConnection::IsBroker { broker } => broker.send_buf(tag, buf), LlmpConnection::IsClient { client } => client.send_buf(tag, buf), @@ -428,7 +428,7 @@ impl LlmpSender where SH: ShMem, { - pub fn new(id: u32, keep_pages_forever: bool) -> Result { + pub fn new(id: u32, keep_pages_forever: bool) -> Result { Ok(Self { id, last_msg_sent: ptr::null_mut(), @@ -451,7 +451,7 @@ where /// Reattach to a vacant out_map, to with a previous sender stored the information in an env before. #[cfg(feature = "std")] - pub fn on_existing_from_env(env_name: &str) -> Result { + pub fn on_existing_from_env(env_name: &str) -> Result { let msg_sent_offset = msg_offset_from_env(env_name)?; Self::on_existing_map(SH::existing_from_env(env_name)?, msg_sent_offset) } @@ -459,7 +459,7 @@ where /// Store the info to this sender to env. /// A new client can reattach to it using on_existing_from_env #[cfg(feature = "std")] - pub fn to_env(&self, env_name: &str) -> Result<(), AflError> { + pub fn to_env(&self, env_name: &str) -> Result<(), Error> { let current_out_map = self.out_maps.last().unwrap(); current_out_map.shmem.write_to_env(env_name)?; current_out_map.msg_to_env(self.last_msg_sent, env_name) @@ -491,7 +491,7 @@ where pub fn on_existing_map( current_out_map: SH, last_msg_sent_offset: Option, - ) -> Result { + ) -> Result { let mut out_map = LlmpSharedMap::existing(current_out_map); let last_msg_sent = match last_msg_sent_offset { Some(offset) => out_map.msg_from_offset(offset)?, @@ -529,7 +529,7 @@ where /// The normal alloc will fail if there is not enough space for buf_len_padded + EOP /// So if alloc_next fails, create new page if necessary, use this function, /// place EOP, commit EOP, reset, alloc again on the new space. - unsafe fn alloc_eop(&mut self) -> Result<*mut LlmpMsg, AflError> { + unsafe fn alloc_eop(&mut self) -> Result<*mut LlmpMsg, Error> { let mut map = self.out_maps.last_mut().unwrap(); let page = map.page_mut(); let last_msg = self.last_msg_sent; @@ -650,7 +650,7 @@ where /// After commiting, the msg shall no longer be altered! /// It will be read by the consuming threads (broker->clients or client->broker) #[inline(never)] // Not inlined to make cpu-level reodering (hopefully?) improbable - unsafe fn send(&mut self, msg: *mut LlmpMsg) -> Result<(), AflError> { + unsafe fn send(&mut self, msg: *mut LlmpMsg) -> Result<(), Error> { if self.last_msg_sent == msg { panic!("Message sent twice!"); } @@ -659,7 +659,7 @@ where } let page = self.out_maps.last_mut().unwrap().page_mut(); if msg.is_null() || !llmp_msg_in_page(page, msg) { - return Err(AflError::Unknown(format!( + return Err(Error::Unknown(format!( "Llmp Message {:?} is null or not in current page", msg ))); @@ -673,7 +673,7 @@ where } /// listener about it using a EOP message. - unsafe fn handle_out_eop(&mut self) -> Result<(), AflError> { + unsafe fn handle_out_eop(&mut self) -> Result<(), Error> { let old_map = self.out_maps.last_mut().unwrap().page_mut(); // Create a new shard page. @@ -710,7 +710,7 @@ where } /// Allocates the next space on this sender page - pub unsafe fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, AflError> { + pub unsafe fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, Error> { match self.alloc_next_if_space(buf_len) { Some(msg) => return Ok(msg), _ => (), @@ -721,7 +721,7 @@ where match self.alloc_next_if_space(buf_len) { Some(msg) => Ok(msg), - None => Err(AflError::Unknown(format!( + None => Err(Error::Unknown(format!( "Error allocating {} bytes in shmap", buf_len ))), @@ -738,14 +738,14 @@ where } /// Allocates a message of the given size, tags it, and sends it off. - pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), AflError> { + pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), Error> { // Make sure we don't reuse already allocated tags if tag == LLMP_TAG_NEW_SHM_CLIENT || tag == LLMP_TAG_END_OF_PAGE || tag == LLMP_TAG_UNINITIALIZED || tag == LLMP_TAG_UNSET { - return Err(AflError::Unknown(format!( + return Err(Error::Unknown(format!( "Reserved tag supplied to send_buf ({:#X})", tag ))); @@ -760,7 +760,7 @@ where } // Describe this cient in a way, that it can be restored later with `Self::on_existing_from_description` - pub fn describe(&self) -> Result { + pub fn describe(&self) -> Result { let map = self.out_maps.last().unwrap(); let last_message_offset = if self.last_msg_sent.is_null() { None @@ -774,7 +774,7 @@ where } // Create this client on an existing map from the given description. acquired with `self.describe` - pub fn on_existing_from_description(description: &LlmpDescription) -> Result { + pub fn on_existing_from_description(description: &LlmpDescription) -> Result { Self::on_existing_map( SH::existing_from_description(&description.shmem)?, description.last_message_offset, @@ -802,7 +802,7 @@ where { /// Reattach to a vacant recv_map, to with a previous sender stored the information in an env before. #[cfg(feature = "std")] - pub fn on_existing_from_env(env_name: &str) -> Result { + pub fn on_existing_from_env(env_name: &str) -> Result { Self::on_existing_map( SH::existing_from_env(env_name)?, msg_offset_from_env(env_name)?, @@ -812,7 +812,7 @@ where /// Store the info to this receiver to env. /// A new client can reattach to it using on_existing_from_env #[cfg(feature = "std")] - pub fn to_env(&self, env_name: &str) -> Result<(), AflError> { + pub fn to_env(&self, env_name: &str) -> Result<(), Error> { let current_out_map = &self.current_recv_map; current_out_map.shmem.write_to_env(env_name)?; current_out_map.msg_to_env(self.last_msg_recvd, env_name) @@ -824,7 +824,7 @@ where pub fn on_existing_map( current_sender_map: SH, last_msg_recvd_offset: Option, - ) -> Result { + ) -> Result { let mut current_recv_map = LlmpSharedMap::existing(current_sender_map); let last_msg_recvd = match last_msg_recvd_offset { Some(offset) => current_recv_map.msg_from_offset(offset)?, @@ -841,7 +841,7 @@ where // Never inline, to not get some strange effects /// Read next message. #[inline(never)] - unsafe fn recv(&mut self) -> Result, AflError> { + unsafe fn recv(&mut self) -> Result, Error> { /* DBG("recv %p %p\n", page, last_msg); */ compiler_fence(Ordering::SeqCst); let page = self.current_recv_map.page_mut(); @@ -871,7 +871,7 @@ where match ret { Some(msg) => { if !(*msg).in_map(&mut self.current_recv_map) { - return Err(AflError::IllegalState("Unexpected message in map (out of map bounds) - bugy client or tampered shared map detedted!".into())); + return Err(Error::IllegalState("Unexpected message in map (out of map bounds) - bugy client or tampered shared map detedted!".into())); } // Handle special, LLMP internal, messages. match (*msg).tag { @@ -923,7 +923,7 @@ where /// Blocks/spins until the next message gets posted to the page, /// then returns that message. - pub unsafe fn recv_blocking(&mut self) -> Result<*mut LlmpMsg, AflError> { + pub unsafe fn recv_blocking(&mut self) -> Result<*mut LlmpMsg, Error> { let mut current_msg_id = 0; let page = self.current_recv_map.page_mut(); let last_msg = self.last_msg_recvd; @@ -946,7 +946,7 @@ where /// Returns the next message, tag, buf, if avaliable, else None #[inline] - pub fn recv_buf(&mut self) -> Result, AflError> { + pub fn recv_buf(&mut self) -> Result, Error> { unsafe { Ok(match self.recv()? { Some(msg) => Some(( @@ -961,7 +961,7 @@ where /// Returns the next sender, tag, buf, looping until it becomes available #[inline] - pub fn recv_buf_blocking(&mut self) -> Result<(u32, u32, &[u8]), AflError> { + pub fn recv_buf_blocking(&mut self) -> Result<(u32, u32, &[u8]), Error> { unsafe { let msg = self.recv_blocking()?; Ok(( @@ -973,7 +973,7 @@ where } // Describe this cient in a way, that it can be restored later with `Self::on_existing_from_description` - pub fn describe(&self) -> Result { + pub fn describe(&self) -> Result { let map = &self.current_recv_map; let last_message_offset = if self.last_msg_recvd.is_null() { None @@ -987,7 +987,7 @@ where } // Create this client on an existing map from the given description. acquired with `self.describe` - pub fn on_existing_from_description(description: &LlmpDescription) -> Result { + pub fn on_existing_from_description(description: &LlmpDescription) -> Result { Self::on_existing_map( SH::existing_from_description(&description.shmem)?, description.last_message_offset, @@ -1054,14 +1054,14 @@ where /// Gets the offset of a message on this here page. /// Will return IllegalArgument error if msg is not on page. - pub fn msg_to_offset(&self, msg: *const LlmpMsg) -> Result { + pub fn msg_to_offset(&self, msg: *const LlmpMsg) -> Result { unsafe { let page = self.page(); if llmp_msg_in_page(page, msg) { // Cast both sides to u8 arrays, get the offset, then cast the return isize to u64 Ok((msg as *const u8).offset_from((*page).messages.as_ptr() as *const u8) as u64) } else { - Err(AflError::IllegalArgument(format!( + Err(Error::IllegalArgument(format!( "Message (0x{:X}) not in page (0x{:X})", page as u64, msg as u64 ))) @@ -1072,7 +1072,7 @@ where /// Retrieve the stored msg from env_name + _OFFSET. /// It will restore the stored offset by env_name and return the message. #[cfg(feature = "std")] - pub fn msg_from_env(&mut self, map_env_name: &str) -> Result<*mut LlmpMsg, AflError> { + pub fn msg_from_env(&mut self, map_env_name: &str) -> Result<*mut LlmpMsg, Error> { match msg_offset_from_env(map_env_name)? { Some(offset) => self.msg_from_offset(offset), None => Ok(ptr::null_mut()), @@ -1082,7 +1082,7 @@ where /// Store this msg offset to env_name + _OFFSET env variable. /// It can be restored using msg_from_env with the same env_name later. #[cfg(feature = "std")] - pub fn msg_to_env(&self, msg: *const LlmpMsg, map_env_name: &str) -> Result<(), AflError> { + pub fn msg_to_env(&self, msg: *const LlmpMsg, map_env_name: &str) -> Result<(), Error> { if msg.is_null() { env::set_var(&format!("{}_OFFSET", map_env_name), _NULL_ENV_STR) } else { @@ -1096,12 +1096,12 @@ where /// Gets this message from this page, at the indicated offset. /// Will return IllegalArgument error if the offset is out of bounds. - pub fn msg_from_offset(&mut self, offset: u64) -> Result<*mut LlmpMsg, AflError> { + pub fn msg_from_offset(&mut self, offset: u64) -> Result<*mut LlmpMsg, Error> { unsafe { let page = self.page_mut(); let page_size = self.shmem.map().len() - size_of::(); if offset as isize > page_size as isize { - Err(AflError::IllegalArgument(format!( + Err(Error::IllegalArgument(format!( "Msg offset out of bounds (size: {}, requested offset: {})", page_size, offset ))) @@ -1136,7 +1136,7 @@ where SH: ShMem, { /// Create and initialize a new llmp_broker - pub fn new() -> Result { + pub fn new() -> Result { let broker = LlmpBroker { llmp_out: LlmpSender { id: 0, @@ -1153,7 +1153,7 @@ where } /// Allocate the next message on the outgoing map - unsafe fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, AflError> { + unsafe fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, Error> { self.llmp_out.alloc_next(buf_len) } @@ -1172,7 +1172,7 @@ where } /// For internal use: Forward the current message to the out map. - unsafe fn forward_msg(&mut self, msg: *mut LlmpMsg) -> Result<(), AflError> { + unsafe fn forward_msg(&mut self, msg: *mut LlmpMsg) -> Result<(), Error> { let mut out: *mut LlmpMsg = self.alloc_next((*msg).buf_len_padded as usize)?; /* Copy over the whole message. @@ -1193,9 +1193,9 @@ where /// The broker walks all pages and looks for changes, then broadcasts them on /// its own shared page, once. #[inline] - pub fn once(&mut self, on_new_msg: &mut F) -> Result<(), AflError> + pub fn once(&mut self, on_new_msg: &mut F) -> Result<(), Error> where - F: FnMut(u32, Tag, &[u8]) -> Result, + F: FnMut(u32, Tag, &[u8]) -> Result, { compiler_fence(Ordering::SeqCst); for i in 0..self.llmp_clients.len() { @@ -1211,7 +1211,7 @@ where /// 5 millis of sleep can't hurt to keep busywait not at 100% pub fn loop_forever(&mut self, on_new_msg: &mut F, sleep_time: Option) -> ! where - F: FnMut(u32, Tag, &[u8]) -> Result, + F: FnMut(u32, Tag, &[u8]) -> Result, { loop { compiler_fence(Ordering::SeqCst); @@ -1235,7 +1235,7 @@ where } /// Broadcasts the given buf to all lients - pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), AflError> { + pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), Error> { self.llmp_out.send_buf(tag, buf) } @@ -1245,7 +1245,7 @@ where pub fn launch_tcp_listener_on( &mut self, port: u16, - ) -> Result, AflError> { + ) -> Result, Error> { let listener = TcpListener::bind(format!("127.0.0.1:{}", port))?; // accept connections and process them, spawning a new thread for each one println!("Server listening on port {}", port); @@ -1257,7 +1257,7 @@ where pub fn launch_tcp_listener( &mut self, listener: TcpListener, - ) -> Result, AflError> { + ) -> Result, Error> { // Later in the execution, after the initial map filled up, // the current broacast map will will point to a different map. // However, the original map is (as of now) never freed, new clients will start @@ -1336,9 +1336,9 @@ where &mut self, client_id: u32, on_new_msg: &mut F, - ) -> Result<(), AflError> + ) -> Result<(), Error> where - F: FnMut(u32, Tag, &[u8]) -> Result, + F: FnMut(u32, Tag, &[u8]) -> Result, { let mut next_id = self.llmp_clients.len() as u32; @@ -1365,7 +1365,7 @@ where size_of::() ); #[cfg(not(feature = "std"))] - return Err(AflError::Unknown(format!("Broken CLIENT_ADDED msg with incorrect size received. Expected {} but got {}", + return Err(Error::Unknown(format!("Broken CLIENT_ADDED msg with incorrect size received. Expected {} but got {}", (*msg).buf_len_padded, size_of::() ))); @@ -1388,7 +1388,7 @@ where #[cfg(feature = "std")] println!("Error adding client! Ignoring: {:?}", e); #[cfg(not(feature = "std"))] - return Err(AflError::Unknown(format!( + return Err(Error::Unknown(format!( "Error adding client! PANIC! {:?}", e ))); @@ -1448,7 +1448,7 @@ where last_msg_sent_offset: Option, current_broker_map: SH, last_msg_recvd_offset: Option, - ) -> Result { + ) -> Result { Ok(Self { receiver: LlmpReceiver::on_existing_map(current_broker_map, last_msg_recvd_offset)?, sender: LlmpSender::on_existing_map(current_out_map, last_msg_sent_offset)?, @@ -1457,7 +1457,7 @@ where /// Recreate this client from a previous client.to_env #[cfg(feature = "std")] - pub fn on_existing_from_env(env_name: &str) -> Result { + pub fn on_existing_from_env(env_name: &str) -> Result { Ok(Self { sender: LlmpSender::on_existing_from_env(&format!("{}_SENDER", env_name))?, receiver: LlmpReceiver::on_existing_from_env(&format!("{}_RECEIVER", env_name))?, @@ -1467,13 +1467,13 @@ where /// Write the current state to env. /// A new client can attach to exactly the same state by calling on_existing_map. #[cfg(feature = "std")] - pub fn to_env(&self, env_name: &str) -> Result<(), AflError> { + pub fn to_env(&self, env_name: &str) -> Result<(), Error> { self.sender.to_env(&format!("{}_SENDER", env_name))?; self.receiver.to_env(&format!("{}_RECEIVER", env_name)) } /// Describe this client in a way that it can be recreated, for example after crash - fn describe(&self) -> Result { + fn describe(&self) -> Result { Ok(LlmpClientDescription { sender: self.sender.describe()?, receiver: self.receiver.describe()?, @@ -1483,7 +1483,7 @@ where /// Create an existing client from description fn existing_client_from_description( description: &LlmpClientDescription, - ) -> Result { + ) -> Result { Ok(Self { sender: LlmpSender::on_existing_from_description(&description.sender)?, receiver: LlmpReceiver::on_existing_from_description(&description.receiver)?, @@ -1502,7 +1502,7 @@ where } /// Creates a new LlmpClient - pub fn new(initial_broker_map: LlmpSharedMap) -> Result { + pub fn new(initial_broker_map: LlmpSharedMap) -> Result { Ok(Self { sender: LlmpSender { id: 0, @@ -1524,12 +1524,12 @@ where } /// Commits a msg to the client's out map - pub unsafe fn send(&mut self, msg: *mut LlmpMsg) -> Result<(), AflError> { + pub unsafe fn send(&mut self, msg: *mut LlmpMsg) -> Result<(), Error> { self.sender.send(msg) } /// Allocates a message of the given size, tags it, and sends it off. - pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), AflError> { + pub fn send_buf(&mut self, tag: Tag, buf: &[u8]) -> Result<(), Error> { self.sender.send_buf(tag, buf) } @@ -1538,7 +1538,7 @@ where &mut self, shm_str: &[u8; 20], shm_id: usize, - ) -> Result<(), AflError> { + ) -> Result<(), Error> { // We write this by hand to get around checks in send_buf unsafe { let msg = self @@ -1555,45 +1555,45 @@ where /// A client receives a broadcast message. /// Returns null if no message is availiable #[inline] - pub unsafe fn recv(&mut self) -> Result, AflError> { + pub unsafe fn recv(&mut self) -> Result, Error> { self.receiver.recv() } /// A client blocks/spins until the next message gets posted to the page, /// then returns that message. #[inline] - pub unsafe fn recv_blocking(&mut self) -> Result<*mut LlmpMsg, AflError> { + pub unsafe fn recv_blocking(&mut self) -> Result<*mut LlmpMsg, Error> { self.receiver.recv_blocking() } /// The current page could have changed in recv (EOP) /// Alloc the next message, internally handling end of page by allocating a new one. #[inline] - pub unsafe fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, AflError> { + pub unsafe fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, Error> { self.sender.alloc_next(buf_len) } /// Returns the next message, tag, buf, if avaliable, else None #[inline] - pub fn recv_buf(&mut self) -> Result, AflError> { + pub fn recv_buf(&mut self) -> Result, Error> { self.receiver.recv_buf() } /// Receives a buf from the broker, looping until a messages becomes avaliable #[inline] - pub fn recv_buf_blocking(&mut self) -> Result<(u32, u32, &[u8]), AflError> { + pub fn recv_buf_blocking(&mut self) -> Result<(u32, u32, &[u8]), Error> { self.receiver.recv_buf_blocking() } #[cfg(feature = "std")] /// Creates a new LlmpClient, reading the map id and len from env - pub fn create_using_env(env_var: &str) -> Result { + pub fn create_using_env(env_var: &str) -> Result { Self::new(LlmpSharedMap::existing(SH::existing_from_env(env_var)?)) } #[cfg(feature = "std")] /// Create a LlmpClient, getting the ID from a given port - pub fn create_attach_to_tcp(port: u16) -> Result { + pub fn create_attach_to_tcp(port: u16) -> Result { let mut stream = TcpStream::connect(format!("127.0.0.1:{}", port))?; println!("Connected to port {}", port); @@ -1624,18 +1624,18 @@ mod tests { Tag, }; #[cfg(feature = "std")] - use crate::bolts::shmem::AflShmem; + use crate::bolts::shmem::UnixShMem; #[cfg(feature = "std")] #[test] pub fn llmp_connection() { - let mut broker = match LlmpConnection::::on_port(1337).unwrap() { + let mut broker = match LlmpConnection::::on_port(1337).unwrap() { IsClient { client: _ } => panic!("Could not bind to port as broker"), IsBroker { broker } => broker, }; // Add the first client (2nd, actually, because of the tcp listener client) - let mut client = match LlmpConnection::::on_port(1337).unwrap() { + let mut client = match LlmpConnection::::on_port(1337).unwrap() { IsBroker { broker: _ } => panic!("Second connect should be a client!"), IsClient { client } => client, }; @@ -1659,7 +1659,7 @@ mod tests { } /* recreate the client from env, check if it still works */ - client = LlmpClient::::on_existing_from_env("_ENV_TEST").unwrap(); + client = LlmpClient::::on_existing_from_env("_ENV_TEST").unwrap(); client.send_buf(tag, &arr).unwrap(); diff --git a/afl/src/bolts/serdeany.rs b/afl/src/bolts/serdeany.rs index 53e58fcfda..70b1937e5a 100644 --- a/afl/src/bolts/serdeany.rs +++ b/afl/src/bolts/serdeany.rs @@ -82,7 +82,7 @@ macro_rules! create_serde_registry_for_trait { use $crate::bolts::serdeany::{ pack_type_id, unpack_type_id, DeserializeCallback, DeserializeCallbackSeed, }; - use $crate::AflError; + use $crate::Error; pub struct BoxDynVisitor {} impl<'de> serde::de::Visitor<'de> for BoxDynVisitor { @@ -398,8 +398,8 @@ macro_rules! create_serde_registry_for_trait { #[inline] pub fn for_each( &self, - func: fn(&TypeId, &Box) -> Result<(), AflError>, - ) -> Result<(), AflError> { + func: fn(&TypeId, &Box) -> Result<(), Error>, + ) -> Result<(), Error> { for (id, h) in self.map.iter() { for x in h.values() { func(&pack_type_id(*id), x)?; @@ -411,8 +411,8 @@ macro_rules! create_serde_registry_for_trait { #[inline] pub fn for_each_mut( &mut self, - func: fn(&TypeId, &mut Box) -> Result<(), AflError>, - ) -> Result<(), AflError> { + func: fn(&TypeId, &mut Box) -> Result<(), Error>, + ) -> Result<(), Error> { for (id, h) in self.map.iter_mut() { for x in h.values_mut() { func(&pack_type_id(*id), x)?; diff --git a/afl/src/bolts/shmem.rs b/afl/src/bolts/shmem.rs index b9de3e70ab..6b614a93ac 100644 --- a/afl/src/bolts/shmem.rs +++ b/afl/src/bolts/shmem.rs @@ -3,7 +3,7 @@ #[cfg(feature = "std")] #[cfg(unix)] -pub use shmem::AflShmem; +pub use shmem::UnixShMem; use alloc::string::{String, ToString}; use core::fmt::Debug; @@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize}; #[cfg(feature = "std")] use std::env; -use crate::AflError; +use crate::Error; /// Description of a shared map. /// May be used to restore the map by id. @@ -26,19 +26,19 @@ pub struct ShMemDescription { /// A Shared map pub trait ShMem: Sized + Debug { /// Creates a new map with the given size - fn new_map(map_size: usize) -> Result; + fn new_map(map_size: usize) -> Result; /// Creates a new reference to the same map - fn clone_ref(old_ref: &Self) -> Result { + fn clone_ref(old_ref: &Self) -> Result { Self::existing_from_shm_slice(old_ref.shm_slice(), old_ref.map().len()) } /// Creates a nes variable with the given name, strigified to 20 bytes. fn existing_from_shm_slice(map_str_bytes: &[u8; 20], map_size: usize) - -> Result; + -> Result; /// Initialize from a shm_str with fixed len of 20 - fn existing_from_shm_str(shm_str: &str, map_size: usize) -> Result { + fn existing_from_shm_str(shm_str: &str, map_size: usize) -> Result { let mut slice: [u8; 20] = [0; 20]; for (i, val) in shm_str.as_bytes().iter().enumerate() { slice[i] = *val; @@ -73,13 +73,13 @@ pub trait ShMem: Sized + Debug { } /// Create a map from a map description - fn existing_from_description(description: &ShMemDescription) -> Result { + fn existing_from_description(description: &ShMemDescription) -> Result { Self::existing_from_shm_slice(&description.str_bytes, description.size) } /// Write this map's config to env #[cfg(feature = "std")] - fn write_to_env(&self, env_name: &str) -> Result<(), AflError> { + fn write_to_env(&self, env_name: &str) -> Result<(), Error> { let map_size = self.map().len(); let map_size_env = format!("{}_SIZE", env_name); env::set_var(env_name, self.shm_str()); @@ -89,7 +89,7 @@ pub trait ShMem: Sized + Debug { /// Reads an existing map config from env vars, then maps it #[cfg(feature = "std")] - fn existing_from_env(env_name: &str) -> Result { + fn existing_from_env(env_name: &str) -> Result { let map_shm_str = env::var(env_name)?; let map_size = str::parse::(&env::var(format!("{}_SIZE", env_name))?)?; Self::existing_from_shm_str(&map_shm_str, map_size) @@ -104,7 +104,7 @@ pub mod shmem { use libc::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_ushort, c_void}; use std::ffi::CStr; - use crate::AflError; + use crate::Error; use super::ShMem; @@ -158,7 +158,7 @@ pub mod shmem { /// The default Sharedmap impl for unix using shmctl & shmget #[cfg(unix)] #[derive(Clone, Debug)] - pub struct AflShmem { + pub struct UnixShMem { pub shm_str: [u8; 20], pub shm_id: c_int, pub map: *mut u8, @@ -166,18 +166,18 @@ pub mod shmem { } #[cfg(unix)] - impl ShMem for AflShmem { + impl ShMem for UnixShMem { fn existing_from_shm_slice( map_str_bytes: &[u8; 20], map_size: usize, - ) -> Result { + ) -> Result { unsafe { let str_bytes = map_str_bytes as *const [u8; 20] as *const libc::c_char; Self::from_str(CStr::from_ptr(str_bytes), map_size) } } - fn new_map(map_size: usize) -> Result { + fn new_map(map_size: usize) -> Result { Self::new(map_size) } @@ -195,7 +195,7 @@ pub mod shmem { } /// Deinit sharedmaps on drop - impl Drop for AflShmem { + impl Drop for UnixShMem { fn drop(&mut self) { unsafe { afl_shmem_deinit(self); @@ -205,8 +205,8 @@ pub mod shmem { /// Create an uninitialized shmap #[cfg(unix)] - const fn afl_shmem_unitialized() -> AflShmem { - AflShmem { + const fn afl_shmem_unitialized() -> UnixShMem { + UnixShMem { shm_str: [0; 20], shm_id: -1, map: 0 as *mut c_uchar, @@ -215,27 +215,27 @@ pub mod shmem { } #[cfg(unix)] - impl AflShmem { - pub fn from_str(shm_str: &CStr, map_size: usize) -> Result { + impl UnixShMem { + pub fn from_str(shm_str: &CStr, map_size: usize) -> Result { let mut ret = afl_shmem_unitialized(); let map = unsafe { afl_shmem_by_str(&mut ret, shm_str, map_size) }; if map != 0 as *mut u8 { Ok(ret) } else { - Err(AflError::Unknown(format!( + Err(Error::Unknown(format!( "Could not allocate map with id {:?} and size {}", shm_str, map_size ))) } } - pub fn new(map_size: usize) -> Result { + pub fn new(map_size: usize) -> Result { let mut ret = afl_shmem_unitialized(); let map = unsafe { afl_shmem_init(&mut ret, map_size) }; if map != 0 as *mut u8 { Ok(ret) } else { - Err(AflError::Unknown(format!( + Err(Error::Unknown(format!( "Could not allocate map of size {}", map_size ))) @@ -244,7 +244,7 @@ pub mod shmem { } /// Deinitialize this shmem instance - unsafe fn afl_shmem_deinit(shm: *mut AflShmem) { + unsafe fn afl_shmem_deinit(shm: *mut UnixShMem) { if shm.is_null() || (*shm).map.is_null() { /* Serialized map id */ // Not set or not initialized; @@ -257,7 +257,7 @@ pub mod shmem { /// Functions to create Shared memory region, for observation channels and /// opening inputs and stuff. - unsafe fn afl_shmem_init(shm: *mut AflShmem, map_size: usize) -> *mut c_uchar { + unsafe fn afl_shmem_init(shm: *mut UnixShMem, map_size: usize) -> *mut c_uchar { (*shm).map_size = map_size; (*shm).map = 0 as *mut c_uchar; (*shm).shm_id = shmget( @@ -290,7 +290,7 @@ pub mod shmem { /// Uses a shmap id string to open a shared map unsafe fn afl_shmem_by_str( - shm: *mut AflShmem, + shm: *mut UnixShMem, shm_str: &CStr, map_size: usize, ) -> *mut c_uchar { @@ -324,7 +324,7 @@ pub mod shmem { mod tests { #[cfg(feature = "std")] - use super::{AflShmem, ShMem}; + use super::{UnixShMem, ShMem}; #[cfg(feature = "std")] #[test] @@ -333,7 +333,7 @@ mod tests { shm_str[0] = 'A' as u8; shm_str[1] = 'B' as u8; shm_str[2] = 'C' as u8; - let faux_shmem = AflShmem { + let faux_shmem = UnixShMem { shm_id: 0, shm_str, map: 0 as *mut u8, diff --git a/afl/src/corpus/inmemory.rs b/afl/src/corpus/inmemory.rs index bb80c06e94..83b63edfa1 100644 --- a/afl/src/corpus/inmemory.rs +++ b/afl/src/corpus/inmemory.rs @@ -5,7 +5,7 @@ use core::{cell::RefCell, marker::PhantomData}; use serde::{Deserialize, Serialize}; use crate::{ - corpus::Corpus, corpus::HasTestcaseVec, corpus::Testcase, inputs::Input, utils::Rand, AflError, + corpus::Corpus, corpus::HasTestcaseVec, corpus::Testcase, inputs::Input, utils::Rand, Error, }; /// A corpus handling all important fuzzing in memory. @@ -41,9 +41,9 @@ where { /// Gets the next entry #[inline] - fn next(&mut self, rand: &mut R) -> Result<(&RefCell>, usize), AflError> { + fn next(&mut self, rand: &mut R) -> Result<(&RefCell>, usize), Error> { if self.count() == 0 { - Err(AflError::Empty("No entries in corpus".to_owned())) + Err(Error::Empty("No entries in corpus".to_owned())) } else { let len = { self.entries().len() }; let id = rand.below(len as u64) as usize; diff --git a/afl/src/corpus/mod.rs b/afl/src/corpus/mod.rs index 138311d6a4..ae04aaf5dd 100644 --- a/afl/src/corpus/mod.rs +++ b/afl/src/corpus/mod.rs @@ -18,7 +18,7 @@ pub use queue::QueueCorpus; use alloc::{borrow::ToOwned, vec::Vec}; use core::{cell::RefCell, ptr}; -use crate::{inputs::Input, utils::Rand, AflError}; +use crate::{inputs::Input, utils::Rand, Error}; /// A way to obtain the containing testcase entries pub trait HasTestcaseVec @@ -52,9 +52,9 @@ where } /// Replaces the testcase at the given idx - fn replace(&mut self, idx: usize, testcase: Testcase) -> Result<(), AflError> { + fn replace(&mut self, idx: usize, testcase: Testcase) -> Result<(), Error> { if self.entries_mut().len() < idx { - return Err(AflError::KeyNotFound(format!( + return Err(Error::KeyNotFound(format!( "Index {} out of bounds", idx ))); @@ -84,9 +84,9 @@ where /// Gets a random entry #[inline] - fn random_entry(&self, rand: &mut R) -> Result<(&RefCell>, usize), AflError> { + fn random_entry(&self, rand: &mut R) -> Result<(&RefCell>, usize), Error> { if self.count() == 0 { - Err(AflError::Empty("No entries in corpus".to_owned())) + Err(Error::Empty("No entries in corpus".to_owned())) } else { let len = { self.entries().len() }; let id = rand.below(len as u64) as usize; @@ -96,7 +96,7 @@ where // TODO: IntoIter /// Gets the next entry - fn next(&mut self, rand: &mut R) -> Result<(&RefCell>, usize), AflError>; + fn next(&mut self, rand: &mut R) -> Result<(&RefCell>, usize), Error>; /// Returns the testacase we currently use fn current_testcase(&self) -> (&RefCell>, usize); diff --git a/afl/src/corpus/ondisk.rs b/afl/src/corpus/ondisk.rs index f42e1c332e..00dd84e852 100644 --- a/afl/src/corpus/ondisk.rs +++ b/afl/src/corpus/ondisk.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use std::path::PathBuf; use crate::{ - corpus::Corpus, corpus::HasTestcaseVec, corpus::Testcase, inputs::Input, utils::Rand, AflError, + corpus::Corpus, corpus::HasTestcaseVec, corpus::Testcase, inputs::Input, utils::Rand, Error, }; /// A corpus able to store testcases to disk, and load them from disk, when they are being used. @@ -73,9 +73,9 @@ where /// Gets the next entry #[inline] - fn next(&mut self, rand: &mut R) -> Result<(&RefCell>, usize), AflError> { + fn next(&mut self, rand: &mut R) -> Result<(&RefCell>, usize), Error> { if self.count() == 0 { - Err(AflError::Empty("No entries in corpus".to_owned())) + Err(Error::Empty("No entries in corpus".to_owned())) } else { let len = { self.entries().len() }; let id = rand.below(len as u64) as usize; diff --git a/afl/src/corpus/queue.rs b/afl/src/corpus/queue.rs index 030ec956a7..08a7fa729f 100644 --- a/afl/src/corpus/queue.rs +++ b/afl/src/corpus/queue.rs @@ -5,7 +5,7 @@ use core::{cell::RefCell, marker::PhantomData}; use serde::{Deserialize, Serialize}; use crate::{ - corpus::Corpus, corpus::HasTestcaseVec, corpus::Testcase, inputs::Input, utils::Rand, AflError, + corpus::Corpus, corpus::HasTestcaseVec, corpus::Testcase, inputs::Input, utils::Rand, Error, }; /// A Queue-like corpus, wrapping an existing Corpus instance @@ -64,7 +64,7 @@ where /// Gets a random entry #[inline] - fn random_entry(&self, rand: &mut R) -> Result<(&RefCell>, usize), AflError> { + fn random_entry(&self, rand: &mut R) -> Result<(&RefCell>, usize), Error> { self.corpus.random_entry(rand) } @@ -76,10 +76,10 @@ where /// Gets the next entry #[inline] - fn next(&mut self, _rand: &mut R) -> Result<(&RefCell>, usize), AflError> { + fn next(&mut self, _rand: &mut R) -> Result<(&RefCell>, usize), Error> { self.pos += 1; if self.corpus.count() == 0 { - return Err(AflError::Empty("Corpus".to_owned())); + return Err(Error::Empty("Corpus".to_owned())); } if self.pos > self.corpus.count() { // TODO: Always loop or return informational error? diff --git a/afl/src/corpus/testcase.rs b/afl/src/corpus/testcase.rs index 097d0b474f..7dabd96733 100644 --- a/afl/src/corpus/testcase.rs +++ b/afl/src/corpus/testcase.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use crate::{ bolts::serdeany::{SerdeAny, SerdeAnyMap}, inputs::Input, - AflError, + Error, }; /// An entry in the Testcase Corpus @@ -34,7 +34,7 @@ where I: Input, { /// Returns this testcase with a loaded input - pub fn load_input(&mut self) -> Result<&I, AflError> { + pub fn load_input(&mut self) -> Result<&I, Error> { if self.input.is_none() { self.input = Some(I::from_file(self.filename.as_ref().unwrap())?); } @@ -42,7 +42,7 @@ where } /// Store the input to disk if possible - pub fn store_input(&mut self) -> Result { + pub fn store_input(&mut self) -> Result { let fname; match self.filename() { Some(f) => { diff --git a/afl/src/events/llmp.rs b/afl/src/events/llmp.rs index 49869a4a63..ce436e2a22 100644 --- a/afl/src/events/llmp.rs +++ b/afl/src/events/llmp.rs @@ -10,7 +10,7 @@ use std::{env, process::Command}; #[cfg(feature = "std")] #[cfg(unix)] -use crate::bolts::shmem::AflShmem; +use crate::bolts::shmem::UnixShMem; use crate::{ bolts::{ llmp::{self, LlmpClient, LlmpClientDescription, Tag}, @@ -24,7 +24,7 @@ use crate::{ state::State, stats::Stats, utils::Rand, - AflError, + Error, }; /// Forward this to the client @@ -53,7 +53,7 @@ where #[cfg(feature = "std")] #[cfg(unix)] -impl LlmpEventManager +impl LlmpEventManager where I: Input, ST: Stats, @@ -62,7 +62,7 @@ where /// If the port is not yet bound, it will act as broker /// Else, it will act as client. #[cfg(feature = "std")] - pub fn new_on_port_std(stats: ST, port: u16) -> Result { + pub fn new_on_port_std(stats: ST, port: u16) -> Result { Ok(Self { stats: Some(stats), llmp: llmp::LlmpConnection::on_port(port)?, @@ -71,9 +71,9 @@ where } /// If a client respawns, it may reuse the existing connection, previously stored by LlmpClient::to_env - /// Std uses AflShmem. + /// Std uses UnixShMem. #[cfg(feature = "std")] - pub fn existing_client_from_env_std(env_name: &str) -> Result { + pub fn existing_client_from_env_std(env_name: &str) -> Result { Self::existing_client_from_env(env_name) } } @@ -100,7 +100,7 @@ where /// If the port is not yet bound, it will act as broker /// Else, it will act as client. #[cfg(feature = "std")] - pub fn new_on_port(stats: ST, port: u16) -> Result { + pub fn new_on_port(stats: ST, port: u16) -> Result { Ok(Self { stats: Some(stats), llmp: llmp::LlmpConnection::on_port(port)?, @@ -110,7 +110,7 @@ where /// If a client respawns, it may reuse the existing connection, previously stored by LlmpClient::to_env #[cfg(feature = "std")] - pub fn existing_client_from_env(env_name: &str) -> Result { + pub fn existing_client_from_env(env_name: &str) -> Result { Ok(Self { stats: None, llmp: llmp::LlmpConnection::IsClient { @@ -123,14 +123,14 @@ where } /// Describe the client event mgr's llmp parts in a restorable fashion - pub fn describe(&self) -> Result { + pub fn describe(&self) -> Result { self.llmp.describe() } /// Create an existing client from description pub fn existing_client_from_description( description: &LlmpClientDescription, - ) -> Result { + ) -> Result { Ok(Self { stats: None, llmp: llmp::LlmpConnection::existing_client_from_description(description)?, @@ -169,7 +169,7 @@ where } /// Run forever in the broker - pub fn broker_loop(&mut self) -> Result<(), AflError> { + pub fn broker_loop(&mut self) -> Result<(), Error> { match &mut self.llmp { llmp::LlmpConnection::IsBroker { broker } => { let stats = self.stats.as_mut().unwrap(); @@ -190,7 +190,7 @@ where Some(Duration::from_millis(5)), ); } - _ => Err(AflError::IllegalState( + _ => Err(Error::IllegalState( "Called broker loop in the client".into(), )), } @@ -201,7 +201,7 @@ where stats: &mut ST, sender_id: u32, event: &Event, - ) -> Result { + ) -> Result { match &event { Event::NewTestcase { input: _, @@ -257,7 +257,7 @@ where state: &mut State, _sender_id: u32, event: Event, - ) -> Result<(), AflError> + ) -> Result<(), Error> where C: Corpus, FT: FeedbacksTuple, @@ -284,7 +284,7 @@ where state.add_if_interesting(input, interestingness)?; Ok(()) } - _ => Err(AflError::Unknown(format!( + _ => Err(Error::Unknown(format!( "Received illegal message that message should not have arrived: {:?}.", event.name() ))), @@ -313,7 +313,7 @@ where fn process( &mut self, state: &mut State, - ) -> Result + ) -> Result where C: Corpus, FT: FeedbacksTuple, @@ -352,7 +352,7 @@ where &mut self, _state: &mut State, event: Event, - ) -> Result<(), AflError> + ) -> Result<(), Error> where C: Corpus, FT: FeedbacksTuple, @@ -373,7 +373,7 @@ where pub fn serialize_state_mgr( state: &State, mgr: &LlmpEventManager, -) -> Result, AflError> +) -> Result, Error> where C: Corpus, FT: FeedbacksTuple, @@ -390,7 +390,7 @@ where /// Deserialize the state and corpus tuple, previously serialized with `serialize_state_corpus(...)` pub fn deserialize_state_mgr( state_corpus_serialized: &[u8], -) -> Result<(State, LlmpEventManager), AflError> +) -> Result<(State, LlmpEventManager), Error> where C: Corpus, FT: FeedbacksTuple, @@ -440,7 +440,7 @@ where fn on_restart( &mut self, state: &mut State, - ) -> Result<(), AflError> + ) -> Result<(), Error> where C: Corpus, FT: FeedbacksTuple, @@ -458,7 +458,7 @@ where fn process( &mut self, state: &mut State, - ) -> Result + ) -> Result where C: Corpus, FT: FeedbacksTuple, @@ -473,7 +473,7 @@ where &mut self, state: &mut State, event: Event, - ) -> Result<(), AflError> + ) -> Result<(), Error> where C: Corpus, FT: FeedbacksTuple, @@ -526,7 +526,7 @@ pub fn setup_restarting_mgr( Option>, LlmpRestartingEventManager, ), - AflError, + Error, > where I: Input, diff --git a/afl/src/events/logger.rs b/afl/src/events/logger.rs index 2dad3c6041..67a7bae7b2 100644 --- a/afl/src/events/logger.rs +++ b/afl/src/events/logger.rs @@ -10,7 +10,7 @@ use crate::{ state::State, stats::Stats, utils::Rand, - AflError, + Error, }; /// A simple, single-threaded event manager that just logs @@ -34,7 +34,7 @@ where fn process( &mut self, state: &mut State, - ) -> Result + ) -> Result where C: Corpus, FT: FeedbacksTuple, @@ -54,7 +54,7 @@ where &mut self, _state: &mut State, event: Event, - ) -> Result<(), AflError> + ) -> Result<(), Error> where C: Corpus, FT: FeedbacksTuple, @@ -87,7 +87,7 @@ where stats: &mut ST, _sender_id: u32, event: &Event, - ) -> Result { + ) -> Result { match event { Event::NewTestcase { input: _, @@ -137,7 +137,7 @@ where _state: &mut State, _sender_id: u32, event: Event, - ) -> Result<(), AflError> + ) -> Result<(), Error> where C: Corpus, FT: FeedbacksTuple, @@ -146,7 +146,7 @@ where OFT: FeedbacksTuple, { match event { - _ => Err(AflError::Unknown(format!( + _ => Err(Error::Unknown(format!( "Received illegal message that message should not have arrived: {:?}.", event ))), diff --git a/afl/src/events/mod.rs b/afl/src/events/mod.rs index 09969b56e9..93b3ceaba7 100644 --- a/afl/src/events/mod.rs +++ b/afl/src/events/mod.rs @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; use crate::{ corpus::Corpus, feedbacks::FeedbacksTuple, inputs::Input, observers::ObserversTuple, - state::State, utils::Rand, AflError, + state::State, utils::Rand, Error, }; /// The log event severity @@ -55,9 +55,9 @@ where /// Returns the name of this event fn name(&self) -> &str; /// This method will be called in the broker - fn handle_in_broker(&self) -> Result; + fn handle_in_broker(&self) -> Result; /// This method will be called in the clients after handle_in_broker (unless BrokerEventResult::Handled) was returned in handle_in_broker - fn handle_in_client(&self) -> Result<(), AflError>; + fn handle_in_client(&self) -> Result<(), Error>; } */ @@ -158,14 +158,14 @@ where I: Input, { /// Fire an Event - //fn fire<'a>(&mut self, event: Event) -> Result<(), AflError>; + //fn fire<'a>(&mut self, event: Event) -> Result<(), Error>; /// Lookup for incoming events and process them. /// Return the number of processes events or an error fn process( &mut self, state: &mut State, - ) -> Result + ) -> Result where C: Corpus, FT: FeedbacksTuple, @@ -174,7 +174,7 @@ where OFT: FeedbacksTuple; /// Serialize all observers for this type and manager - fn serialize_observers(&mut self, observers: &OT) -> Result, AflError> + fn serialize_observers(&mut self, observers: &OT) -> Result, Error> where OT: ObserversTuple, { @@ -182,7 +182,7 @@ where } /// Deserialize all observers for this type and manager - fn deserialize_observers(&mut self, observers_buf: &[u8]) -> Result + fn deserialize_observers(&mut self, observers_buf: &[u8]) -> Result where OT: ObserversTuple, { @@ -194,7 +194,7 @@ where fn on_restart( &mut self, _state: &mut State, - ) -> Result<(), AflError> + ) -> Result<(), Error> where C: Corpus, FT: FeedbacksTuple, @@ -214,7 +214,7 @@ where &mut self, _state: &mut State, event: Event, - ) -> Result<(), AflError> + ) -> Result<(), Error> where C: Corpus, FT: FeedbacksTuple, @@ -235,7 +235,7 @@ where fn process( &mut self, _state: &mut State, - ) -> Result + ) -> Result where C: Corpus, FT: FeedbacksTuple, @@ -250,7 +250,7 @@ where &mut self, _state: &mut State, _event: Event, - ) -> Result<(), AflError> + ) -> Result<(), Error> where C: Corpus, FT: FeedbacksTuple, diff --git a/afl/src/executors/inprocess.rs b/afl/src/executors/inprocess.rs index 93b5d36bbf..25804a4d3a 100644 --- a/afl/src/executors/inprocess.rs +++ b/afl/src/executors/inprocess.rs @@ -16,7 +16,7 @@ use crate::{ observers::ObserversTuple, state::State, utils::Rand, - AflError, + Error, }; #[cfg(feature = "std")] @@ -59,7 +59,7 @@ where _state: &mut State, _event_mgr: &mut EM, _input: &I, - ) -> Result<(), AflError> + ) -> Result<(), Error> where R: Rand, FT: FeedbacksTuple, @@ -87,7 +87,7 @@ where _state: &State, _event_mgr: &mut EM, _input: &I, - ) -> Result<(), AflError> + ) -> Result<(), Error> where R: Rand, FT: FeedbacksTuple, @@ -105,7 +105,7 @@ where } #[inline] - fn run_target(&mut self, input: &I) -> Result { + fn run_target(&mut self, input: &I) -> Result { let bytes = input.target_bytes(); let ret = (self.harness_fn)(self, bytes.as_slice()); Ok(ret) diff --git a/afl/src/executors/mod.rs b/afl/src/executors/mod.rs index 0ade5b6728..77b6802a3a 100644 --- a/afl/src/executors/mod.rs +++ b/afl/src/executors/mod.rs @@ -17,7 +17,7 @@ use crate::{ observers::ObserversTuple, state::State, utils::Rand, - AflError, + Error, }; /// How an execution finished. @@ -41,13 +41,13 @@ where /// Reset the state of all the observes linked to this executor #[inline] - fn pre_exec_observers(&mut self) -> Result<(), AflError> { + fn pre_exec_observers(&mut self) -> Result<(), Error> { self.observers_mut().pre_exec_all() } /// Run the post exec hook for all the observes linked to this executor #[inline] - fn post_exec_observers(&mut self) -> Result<(), AflError> { + fn post_exec_observers(&mut self) -> Result<(), Error> { self.observers_mut().post_exec_all() } } @@ -62,9 +62,9 @@ impl Executor for NopExecutor where I: Input + HasTargetBytes, { - fn run_target(&mut self, input: &I) -> Result { + fn run_target(&mut self, input: &I) -> Result { if input.target_bytes().as_slice().len() == 0 { - Err(AflError::Empty("Input Empty".into())) + Err(Error::Empty("Input Empty".into())) } else { Ok(ExitKind::Ok) } @@ -89,7 +89,7 @@ where _state: &mut State, _event_mgr: &mut EM, _input: &I, - ) -> Result<(), AflError> + ) -> Result<(), Error> where R: Rand, FT: FeedbacksTuple, @@ -108,7 +108,7 @@ where _state: &State, _event_mgr: &mut EM, _input: &I, - ) -> Result<(), AflError> + ) -> Result<(), Error> where R: Rand, FT: FeedbacksTuple, @@ -121,7 +121,7 @@ where } /// Instruct the target about the input and run - fn run_target(&mut self, input: &I) -> Result; + fn run_target(&mut self, input: &I) -> Result; } pub trait ExecutorsTuple: MatchType + MatchNameAndType diff --git a/afl/src/feedbacks/map.rs b/afl/src/feedbacks/map.rs index 95efb72228..14f37ffffe 100644 --- a/afl/src/feedbacks/map.rs +++ b/afl/src/feedbacks/map.rs @@ -12,7 +12,7 @@ use crate::{ feedbacks::Feedback, inputs::Input, observers::{MapObserver, Observer, ObserversTuple}, - AflError, + Error, }; pub type MaxMapFeedback = MapFeedback, O>; @@ -108,7 +108,7 @@ where _input: &I, observers: &OT, _exit_kind: ExitKind, - ) -> Result { + ) -> Result { let mut interesting = 0; // TODO optimize let observer = observers.match_name_type::(&self.name).unwrap(); @@ -245,7 +245,7 @@ where O: MapObserver, I: Input, { - fn is_interesting(&mut self, _input: &I) -> Result { + fn is_interesting(&mut self, _input: &I) -> Result { let mut interesting = 0; // TODO optimize @@ -266,14 +266,14 @@ where Ok(interesting) } - fn append_metadata(&mut self, testcase: &mut Testcase) -> Result<(), AflError> { + fn append_metadata(&mut self, testcase: &mut Testcase) -> Result<(), Error> { let meta = MapNoveltiesMetadata::new(core::mem::take(&mut self.novelties)); testcase.add_metadata(meta); Ok(()) } /// Discard the stored metadata in case that the testcase is not added to the corpus - fn discard_metadata(&mut self, _input: &I) -> Result<(), AflError> { + fn discard_metadata(&mut self, _input: &I) -> Result<(), Error> { self.novelties.clear(); Ok(()) } diff --git a/afl/src/feedbacks/mod.rs b/afl/src/feedbacks/mod.rs index f69e017f1a..724b0d4d41 100644 --- a/afl/src/feedbacks/mod.rs +++ b/afl/src/feedbacks/mod.rs @@ -12,7 +12,7 @@ use crate::{ executors::ExitKind, inputs::Input, observers::ObserversTuple, - AflError, + Error, }; /// Feedbacks evaluate the observers. @@ -28,17 +28,17 @@ where input: &I, observers: &OT, exit_kind: ExitKind, - ) -> Result; + ) -> Result; /// Append to the testcase the generated metadata in case of a new corpus item #[inline] - fn append_metadata(&mut self, _testcase: &mut Testcase) -> Result<(), AflError> { + fn append_metadata(&mut self, _testcase: &mut Testcase) -> Result<(), Error> { Ok(()) } /// Discard the stored metadata in case that the testcase is not added to the corpus #[inline] - fn discard_metadata(&mut self, _input: &I) -> Result<(), AflError> { + fn discard_metadata(&mut self, _input: &I) -> Result<(), Error> { Ok(()) } @@ -49,19 +49,19 @@ where /// Example: /// >> The virgin_bits map in AFL needs to be in sync with the corpus #[inline] - fn serialize_state(&mut self) -> Result, AflError> { + fn serialize_state(&mut self) -> Result, Error> { Ok(vec![]) } /// Restore the state from a given vec, priviously stored using `serialize_state` #[inline] - fn deserialize_state(&mut self, serialized_state: &[u8]) -> Result<(), AflError> { + fn deserialize_state(&mut self, serialized_state: &[u8]) -> Result<(), Error> { let _ = serialized_state; Ok(()) } // TODO: Restore_from - fn restore_from(&mut self, restore_from: Self) -> Result<(), AflError> { + fn restore_from(&mut self, restore_from: Self) -> Result<(), Error> { Ok(()) } */ @@ -77,18 +77,18 @@ where input: &I, observers: &OT, exit_kind: ExitKind, - ) -> Result; + ) -> Result; /// Write metadata for this testcase - fn append_metadata_all(&mut self, testcase: &mut Testcase) -> Result<(), AflError>; + fn append_metadata_all(&mut self, testcase: &mut Testcase) -> Result<(), Error>; /// Discards metadata - the end of this input's execution - fn discard_metadata_all(&mut self, input: &I) -> Result<(), AflError>; + fn discard_metadata_all(&mut self, input: &I) -> Result<(), Error>; /* /// Restores the state from each of the containing feedbacks in a list of the same shape. /// Used (prette exclusively) to restore the feedback states after a crash. - fn restore_state_from_all(&mut self, restore_from: &Self) -> Result<(), AflError>; + fn restore_state_from_all(&mut self, restore_from: &Self) -> Result<(), Error>; */ } @@ -102,22 +102,22 @@ where _: &I, _: &OT, _: ExitKind, - ) -> Result { + ) -> Result { Ok(0) } #[inline] - fn append_metadata_all(&mut self, _testcase: &mut Testcase) -> Result<(), AflError> { + fn append_metadata_all(&mut self, _testcase: &mut Testcase) -> Result<(), Error> { Ok(()) } #[inline] - fn discard_metadata_all(&mut self, _input: &I) -> Result<(), AflError> { + fn discard_metadata_all(&mut self, _input: &I) -> Result<(), Error> { Ok(()) } /* - fn restore_state_from_all(&mut self, restore_from: &Self) -> Result<(), AflError> { + fn restore_state_from_all(&mut self, restore_from: &Self) -> Result<(), Error> { Ok(()) } */ @@ -134,23 +134,23 @@ where input: &I, observers: &OT, exit_kind: ExitKind, - ) -> Result { + ) -> Result { Ok(self.0.is_interesting(input, observers, exit_kind.clone())? + self.1.is_interesting_all(input, observers, exit_kind)?) } - fn append_metadata_all(&mut self, testcase: &mut Testcase) -> Result<(), AflError> { + fn append_metadata_all(&mut self, testcase: &mut Testcase) -> Result<(), Error> { self.0.append_metadata(testcase)?; self.1.append_metadata_all(testcase) } - fn discard_metadata_all(&mut self, input: &I) -> Result<(), AflError> { + fn discard_metadata_all(&mut self, input: &I) -> Result<(), Error> { self.0.discard_metadata(input)?; self.1.discard_metadata_all(input) } /* - fn restore_state_from_all(&mut self, restore_from: &Self) -> Result<(), AflError> { + fn restore_state_from_all(&mut self, restore_from: &Self) -> Result<(), Error> { self.0.restore_from(restore_from.0)?; self.1.restore_state_from_all(restore_from.1)?; } @@ -170,7 +170,7 @@ where _input: &I, _observers: &OT, exit_kind: ExitKind, - ) -> Result { + ) -> Result { if exit_kind == ExitKind::Crash { Ok(1) } else { diff --git a/afl/src/generators/mod.rs b/afl/src/generators/mod.rs index f262645ee9..07ab0bd4e6 100644 --- a/afl/src/generators/mod.rs +++ b/afl/src/generators/mod.rs @@ -6,7 +6,7 @@ use core::{cmp::min, marker::PhantomData}; use crate::{ inputs::{bytes::BytesInput, Input}, utils::Rand, - AflError, + Error, }; /// The maximum size of dummy bytes generated by _dummy generator methods @@ -19,7 +19,7 @@ where R: Rand, { /// Generate a new input - fn generate(&mut self, rand: &mut R) -> Result; + fn generate(&mut self, rand: &mut R) -> Result; /// Generate a new dummy input fn generate_dummy(&self) -> I; @@ -39,7 +39,7 @@ impl Generator for RandBytesGenerator where R: Rand, { - fn generate(&mut self, rand: &mut R) -> Result { + fn generate(&mut self, rand: &mut R) -> Result { let mut size = rand.below(self.max_size as u64); if size == 0 { size = 1; @@ -78,7 +78,7 @@ impl Generator for RandPrintablesGenerator where R: Rand, { - fn generate(&mut self, rand: &mut R) -> Result { + fn generate(&mut self, rand: &mut R) -> Result { let mut size = rand.below(self.max_size as u64); if size == 0 { size = 1; diff --git a/afl/src/inputs/mod.rs b/afl/src/inputs/mod.rs index 258cf8e53f..22e1060c30 100644 --- a/afl/src/inputs/mod.rs +++ b/afl/src/inputs/mod.rs @@ -14,13 +14,13 @@ use std::{ use serde::{Deserialize, Serialize}; -use crate::AflError; +use crate::Error; /// An input for the target pub trait Input: Clone + serde::Serialize + serde::de::DeserializeOwned + Debug { #[cfg(feature = "std")] /// Write this input to the file - fn to_file

(&self, path: P) -> Result<(), AflError> + fn to_file

(&self, path: P) -> Result<(), Error> where P: AsRef, { @@ -32,14 +32,14 @@ pub trait Input: Clone + serde::Serialize + serde::de::DeserializeOwned + Debug #[cfg(not(feature = "std"))] /// Write this input to the file - fn to_file

(&self, _path: P) -> Result<(), AflError> + fn to_file

(&self, _path: P) -> Result<(), Error> where { - Err(AflError::NotImplemented("Not suppored in no_std".into())) + Err(Error::NotImplemented("Not suppored in no_std".into())) } /// Load the contents of this input from a file #[cfg(feature = "std")] - fn from_file

(path: P) -> Result + fn from_file

(path: P) -> Result where P: AsRef, { @@ -51,9 +51,9 @@ where { /// Write this input to the file #[cfg(not(feature = "std"))] - fn from_file

(_path: P) -> Result + fn from_file

(_path: P) -> Result where { - Err(AflError::NotImplemented("Not suppored in no_std".into())) + Err(Error::NotImplemented("Not suppored in no_std".into())) } } diff --git a/afl/src/lib.rs b/afl/src/lib.rs index 069d9971c3..24fb73849f 100644 --- a/afl/src/lib.rs +++ b/afl/src/lib.rs @@ -62,7 +62,7 @@ where executor: &mut E, state: &mut State, manager: &mut EM, - ) -> Result { + ) -> Result { let (_, idx) = state.corpus_mut().next(rand)?; self.stages_mut() @@ -78,7 +78,7 @@ where executor: &mut E, state: &mut State, manager: &mut EM, - ) -> Result<(), AflError> { + ) -> Result<(), Error> { let mut last = current_milliseconds(); loop { self.fuzz_one(rand, executor, state, manager)?; @@ -163,7 +163,7 @@ where /// Main error struct for AFL #[derive(Debug)] -pub enum AflError { +pub enum Error { /// Serialization error Serialize(String), /// File related error @@ -187,7 +187,7 @@ pub enum AflError { Unknown(String), } -impl fmt::Display for AflError { +impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Self::Serialize(s) => write!(f, "Error in Serialization: `{0}`", &s), @@ -208,7 +208,7 @@ impl fmt::Display for AflError { } /// Stringify the postcard serializer error -impl From for AflError { +impl From for Error { fn from(err: postcard::Error) -> Self { Self::Serialize(format!("{:?}", err)) } @@ -216,28 +216,28 @@ impl From for AflError { /// Create an AFL Error from io Error #[cfg(feature = "std")] -impl From for AflError { +impl From for Error { fn from(err: io::Error) -> Self { Self::File(err) } } #[cfg(feature = "std")] -impl From for AflError { +impl From for Error { fn from(err: FromUtf8Error) -> Self { Self::Unknown(format!("Could not convert byte to utf-8: {:?}", err)) } } #[cfg(feature = "std")] -impl From for AflError { +impl From for Error { fn from(err: VarError) -> Self { Self::Empty(format!("Could not get env var: {:?}", err)) } } #[cfg(feature = "std")] -impl From for AflError { +impl From for Error { fn from(err: ParseIntError) -> Self { Self::Unknown(format!("Failed to parse Int: {:?}", err)) } diff --git a/afl/src/mutators/mod.rs b/afl/src/mutators/mod.rs index 8f9a3e59c8..d8f0bd9ac2 100644 --- a/afl/src/mutators/mod.rs +++ b/afl/src/mutators/mod.rs @@ -12,7 +12,7 @@ use crate::{ inputs::Input, state::{HasCorpus, HasMetadata}, utils::Rand, - AflError, + Error, }; // TODO mutator stats method that produces something that can be sent with the NewTestcase event @@ -34,7 +34,7 @@ where state: &mut S, input: &mut I, stage_idx: i32, - ) -> Result<(), AflError>; + ) -> Result<(), Error>; /// Post-process given the outcome of the execution fn post_exec( @@ -42,7 +42,7 @@ where _state: &mut S, _is_interesting: u32, _stage_idx: i32, - ) -> Result<(), AflError> { + ) -> Result<(), Error> { Ok(()) } } diff --git a/afl/src/mutators/mutations.rs b/afl/src/mutators/mutations.rs index d01ead16e6..50240ffd01 100644 --- a/afl/src/mutators/mutations.rs +++ b/afl/src/mutators/mutations.rs @@ -3,7 +3,7 @@ use crate::{ mutators::Corpus, mutators::*, utils::Rand, - AflError, + Error, }; use alloc::{borrow::ToOwned, vec::Vec}; @@ -63,7 +63,7 @@ pub enum MutationResult { // TODO maybe the mutator arg is not needed /// The generic function type that identifies mutations pub type MutationFunction = - fn(&mut M, &mut R, &mut S, &mut I) -> Result; + fn(&mut M, &mut R, &mut S, &mut I) -> Result; pub trait ComposedByMutations where @@ -131,7 +131,7 @@ pub fn mutation_bitflip( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, @@ -153,7 +153,7 @@ pub fn mutation_byteflip( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, @@ -175,7 +175,7 @@ pub fn mutation_byteinc( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, @@ -198,7 +198,7 @@ pub fn mutation_bytedec( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, @@ -221,7 +221,7 @@ pub fn mutation_byteneg( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, @@ -243,7 +243,7 @@ pub fn mutation_byterand( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, @@ -265,7 +265,7 @@ pub fn mutation_byteadd( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, @@ -292,7 +292,7 @@ pub fn mutation_wordadd( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, @@ -321,7 +321,7 @@ pub fn mutation_dwordadd( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, @@ -350,7 +350,7 @@ pub fn mutation_qwordadd( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, @@ -379,7 +379,7 @@ pub fn mutation_byteinteresting( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, @@ -402,7 +402,7 @@ pub fn mutation_wordinteresting( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, @@ -430,7 +430,7 @@ pub fn mutation_dwordinteresting( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, @@ -458,7 +458,7 @@ pub fn mutation_bytesdelete( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, @@ -481,7 +481,7 @@ pub fn mutation_bytesexpand( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where M: HasMaxSize, I: Input + HasBytesVec, @@ -510,7 +510,7 @@ pub fn mutation_bytesinsert( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where M: HasMaxSize, I: Input + HasBytesVec, @@ -542,7 +542,7 @@ pub fn mutation_bytesrandinsert( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where M: HasMaxSize, I: Input + HasBytesVec, @@ -574,7 +574,7 @@ pub fn mutation_bytesset( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, @@ -598,7 +598,7 @@ pub fn mutation_bytesrandset( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, @@ -622,7 +622,7 @@ pub fn mutation_bytescopy( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, @@ -646,7 +646,7 @@ pub fn mutation_bytesswap( rand: &mut R, _: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, @@ -673,7 +673,7 @@ pub fn mutation_crossover_insert( rand: &mut R, state: &mut S, input: &mut I, -) -> Result +) -> Result where M: HasMaxSize, C: Corpus, @@ -722,7 +722,7 @@ pub fn mutation_crossover_replace( rand: &mut R, state: &mut S, input: &mut I, -) -> Result +) -> Result where C: Corpus, I: Input + HasBytesVec, @@ -776,7 +776,7 @@ pub fn mutation_splice( rand: &mut R, state: &mut S, input: &mut I, -) -> Result +) -> Result where C: Corpus, I: Input + HasBytesVec, @@ -814,7 +814,7 @@ where } // Converts a hex u8 to its u8 value: 'A' -> 10 etc. -fn from_hex(hex: u8) -> Result { +fn from_hex(hex: u8) -> Result { if hex >= 48 && hex <= 57 { return Ok(hex - 48); } @@ -824,11 +824,11 @@ fn from_hex(hex: u8) -> Result { if hex >= 97 && hex <= 102 { return Ok(hex - 87); } - return Err(AflError::IllegalArgument("".to_owned())); + return Err(Error::IllegalArgument("".to_owned())); } /// Decodes a dictionary token: 'foo\x41\\and\"bar' -> 'fooA\and"bar' -pub fn str_decode(item: &str) -> Result, AflError> { +pub fn str_decode(item: &str) -> Result, Error> { let mut token: Vec = Vec::new(); let item: Vec = item.as_bytes().to_vec(); let backslash: u8 = 92; // '\\' @@ -872,7 +872,7 @@ pub fn add_token(tokens: &mut Vec>, token: &Vec) -> u32 { /// Read a dictionary file and return the number of entries read #[cfg(feature = "std")] -pub fn read_tokens_file(f: &str, tokens: &mut Vec>) -> Result { +pub fn read_tokens_file(f: &str, tokens: &mut Vec>) -> Result { let mut entries = 0; println!("Loading tokens file {:?} ...", &f); @@ -892,13 +892,13 @@ pub fn read_tokens_file(f: &str, tokens: &mut Vec>) -> Result x, _ => { - return Err(AflError::IllegalArgument( + return Err(Error::IllegalArgument( "Illegal line: ".to_owned() + line, )) } }; if line.chars().nth(line.len() - 1) != Some('"') { - return Err(AflError::IllegalArgument( + return Err(Error::IllegalArgument( "Illegal line: ".to_owned() + line, )); } @@ -907,7 +907,7 @@ pub fn read_tokens_file(f: &str, tokens: &mut Vec>) -> Result x, _ => { - return Err(AflError::IllegalArgument( + return Err(Error::IllegalArgument( "Illegal line: ".to_owned() + line, )) } @@ -920,7 +920,7 @@ pub fn read_tokens_file(f: &str, tokens: &mut Vec>) -> Result = match str_decode(item) { Ok(val) => val, Err(_) => { - return Err(AflError::IllegalArgument( + return Err(Error::IllegalArgument( "Illegal line (hex decoding): ".to_owned() + line, )) } diff --git a/afl/src/mutators/scheduled.rs b/afl/src/mutators/scheduled.rs index 483becef6e..9714fedd4c 100644 --- a/afl/src/mutators/scheduled.rs +++ b/afl/src/mutators/scheduled.rs @@ -7,7 +7,7 @@ use crate::{ mutators::{Corpus, *}, state::{HasCorpus, HasMetadata}, utils::Rand, - AflError, + Error, }; pub trait ScheduledMutator: @@ -39,7 +39,7 @@ where state: &mut S, input: &mut I, _stage_idx: i32, - ) -> Result<(), AflError> { + ) -> Result<(), Error> { let num = self.iterations(rand, input); for _ in 0..num { let idx = self.schedule(self.mutations_count(), rand, input); @@ -92,7 +92,7 @@ where state: &mut S, input: &mut I, _stage_idx: i32, - ) -> Result<(), AflError> { + ) -> Result<(), Error> { self.scheduled_mutate(rand, state, input, _stage_idx) } } @@ -201,7 +201,7 @@ where state: &mut S, input: &mut I, stage_idx: i32, - ) -> Result<(), AflError> { + ) -> Result<(), Error> { self.scheduled.mutate(rand, state, input, stage_idx)?; /*let num = self.scheduled.iterations(rand, input); for _ in 0..num { diff --git a/afl/src/mutators/token_mutations.rs b/afl/src/mutators/token_mutations.rs index 2ce7a52ab8..417a6f7dae 100644 --- a/afl/src/mutators/token_mutations.rs +++ b/afl/src/mutators/token_mutations.rs @@ -6,7 +6,7 @@ use crate::{ inputs::{HasBytesVec, Input}, mutators::*, utils::Rand, - AflError, + Error, }; use alloc::vec::Vec; @@ -43,7 +43,7 @@ pub fn mutation_tokeninsert( rand: &mut R, state: &mut S, input: &mut I, -) -> Result +) -> Result where M: HasMaxSize, I: Input + HasBytesVec, @@ -89,7 +89,7 @@ pub fn mutation_tokenreplace( rand: &mut R, state: &mut S, input: &mut I, -) -> Result +) -> Result where I: Input + HasBytesVec, R: Rand, diff --git a/afl/src/observers/map.rs b/afl/src/observers/map.rs index 0b4254845e..01811cf81b 100644 --- a/afl/src/observers/map.rs +++ b/afl/src/observers/map.rs @@ -7,7 +7,7 @@ use crate::{ tuples::Named, }, observers::Observer, - AflError, + Error, }; /// A MapObserver observes the static map, as oftentimes used for afl-like coverage information @@ -37,7 +37,7 @@ where /// Reset the map #[inline] - fn reset_map(&mut self) -> Result<(), AflError> { + fn reset_map(&mut self) -> Result<(), Error> { // Normal memset, see https://rust.godbolt.org/z/Trs5hv let initial = self.initial(); let cnt = self.usable_count(); @@ -67,7 +67,7 @@ where T: Default + Copy + 'static + serde::Serialize + serde::de::DeserializeOwned, { #[inline] - fn pre_exec(&mut self) -> Result<(), AflError> { + fn pre_exec(&mut self) -> Result<(), Error> { self.reset_map() } } @@ -157,7 +157,7 @@ where T: Default + Copy + 'static + serde::Serialize + serde::de::DeserializeOwned, { #[inline] - fn pre_exec(&mut self) -> Result<(), AflError> { + fn pre_exec(&mut self) -> Result<(), Error> { self.reset_map() } } @@ -271,12 +271,12 @@ where M: MapObserver, { #[inline] - fn pre_exec(&mut self) -> Result<(), AflError> { + fn pre_exec(&mut self) -> Result<(), Error> { self.reset_map() } #[inline] - fn post_exec(&mut self) -> Result<(), AflError> { + fn post_exec(&mut self) -> Result<(), Error> { for x in self.map_mut().iter_mut() { *x = COUNT_CLASS_LOOKUP[*x as usize]; } diff --git a/afl/src/observers/mod.rs b/afl/src/observers/mod.rs index 152ac9bfd3..6edd74ef88 100644 --- a/afl/src/observers/mod.rs +++ b/afl/src/observers/mod.rs @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize}; use crate::{ bolts::tuples::{MatchNameAndType, MatchType, Named, TupleList}, utils::current_time, - AflError, + Error, }; /// Observers observe different information about the target. @@ -16,16 +16,16 @@ use crate::{ pub trait Observer: Named + serde::Serialize + serde::de::DeserializeOwned + 'static { /// The testcase finished execution, calculate any changes. #[inline] - fn flush(&mut self) -> Result<(), AflError> { + fn flush(&mut self) -> Result<(), Error> { Ok(()) } /// Resets the observer - fn pre_exec(&mut self) -> Result<(), AflError>; + fn pre_exec(&mut self) -> Result<(), Error>; /// This function is executed after each fuzz run #[inline] - fn post_exec(&mut self) -> Result<(), AflError> { + fn post_exec(&mut self) -> Result<(), Error> { Ok(()) } @@ -35,13 +35,13 @@ pub trait Observer: Named + serde::Serialize + serde::de::DeserializeOwned + 'st /// Example: /// >> The virgin_bits map in AFL needs to be in sync with the corpus #[inline] - fn serialize_state(&mut self) -> Result, AflError> { + fn serialize_state(&mut self) -> Result, Error> { Ok(vec![]) } /// Restore the state from a given vec, priviously stored using `serialize_state` #[inline] - fn deserialize_state(&mut self, serialized_state: &[u8]) -> Result<(), AflError> { + fn deserialize_state(&mut self, serialized_state: &[u8]) -> Result<(), Error> { let _ = serialized_state; Ok(()) } @@ -53,29 +53,29 @@ pub trait ObserversTuple: { /// Reset all executors in the tuple /// This is called right before the next execution. - fn pre_exec_all(&mut self) -> Result<(), AflError>; + fn pre_exec_all(&mut self) -> Result<(), Error>; /// Do whatever you need to do after a run. /// This is called right after the last execution - fn post_exec_all(&mut self) -> Result<(), AflError>; + fn post_exec_all(&mut self) -> Result<(), Error>; //fn for_each(&self, f: fn(&dyn Observer)); //fn for_each_mut(&mut self, f: fn(&mut dyn Observer)); /// Serialize this tuple to a buf - fn serialize(&self) -> Result, AflError> { + fn serialize(&self) -> Result, Error> { Ok(postcard::to_allocvec(&self)?) } /// Deserilaize - fn deserialize(&self, serialized: &[u8]) -> Result { + fn deserialize(&self, serialized: &[u8]) -> Result { Ok(postcard::from_bytes(serialized)?) } } impl ObserversTuple for () { - fn pre_exec_all(&mut self) -> Result<(), AflError> { + fn pre_exec_all(&mut self) -> Result<(), Error> { Ok(()) } - fn post_exec_all(&mut self) -> Result<(), AflError> { + fn post_exec_all(&mut self) -> Result<(), Error> { Ok(()) } @@ -88,12 +88,12 @@ where Head: Observer, Tail: ObserversTuple + TupleList, { - fn pre_exec_all(&mut self) -> Result<(), AflError> { + fn pre_exec_all(&mut self) -> Result<(), Error> { self.0.pre_exec()?; self.1.pre_exec_all() } - fn post_exec_all(&mut self) -> Result<(), AflError> { + fn post_exec_all(&mut self) -> Result<(), Error> { self.0.post_exec()?; self.1.post_exec_all() } @@ -129,13 +129,13 @@ impl TimeObserver { } impl Observer for TimeObserver { - fn pre_exec(&mut self) -> Result<(), AflError> { + fn pre_exec(&mut self) -> Result<(), Error> { self.last_runtime = None; self.start_time = current_time(); Ok(()) } - fn post_exec(&mut self) -> Result<(), AflError> { + fn post_exec(&mut self) -> Result<(), Error> { self.last_runtime = Some(current_time() - self.start_time); Ok(()) } diff --git a/afl/src/stages/mod.rs b/afl/src/stages/mod.rs index 78185d75ef..2ea67a3a03 100644 --- a/afl/src/stages/mod.rs +++ b/afl/src/stages/mod.rs @@ -11,7 +11,7 @@ use crate::{ observers::ObserversTuple, state::State, utils::Rand, - AflError, + Error, }; /// A stage is one step in the fuzzing process. @@ -36,7 +36,7 @@ where state: &mut State, manager: &mut EM, corpus_idx: usize, - ) -> Result<(), AflError>; + ) -> Result<(), Error>; } pub trait StagesTuple @@ -58,7 +58,7 @@ where state: &mut State, manager: &mut EM, corpus_idx: usize, - ) -> Result<(), AflError>; + ) -> Result<(), Error>; fn for_each(&self, f: fn(&dyn Stage)); fn for_each_mut(&mut self, f: fn(&mut dyn Stage)); } @@ -82,7 +82,7 @@ where _state: &mut State, _manager: &mut EM, _corpus_idx: usize, - ) -> Result<(), AflError> { + ) -> Result<(), Error> { Ok(()) } fn for_each(&self, _f: fn(&dyn Stage)) {} @@ -111,7 +111,7 @@ where state: &mut State, manager: &mut EM, corpus_idx: usize, - ) -> Result<(), AflError> { + ) -> Result<(), Error> { self.0.perform(rand, executor, state, manager, corpus_idx)?; self.1 .perform_all(rand, executor, state, manager, corpus_idx) diff --git a/afl/src/stages/mutational.rs b/afl/src/stages/mutational.rs index f776abb29f..9c6c7fbf3a 100644 --- a/afl/src/stages/mutational.rs +++ b/afl/src/stages/mutational.rs @@ -11,7 +11,7 @@ use crate::{ stages::Stage, state::{HasCorpus, State}, utils::Rand, - AflError, + Error, }; // TODO multi mutators stage @@ -54,7 +54,7 @@ where state: &mut State, manager: &mut EM, corpus_idx: usize, - ) -> Result<(), AflError> { + ) -> Result<(), Error> { let num = self.iterations(rand); for i in 0..num { let mut input_mut = state @@ -142,7 +142,7 @@ where state: &mut State, manager: &mut EM, corpus_idx: usize, - ) -> Result<(), AflError> { + ) -> Result<(), Error> { self.perform_mutational(rand, executor, state, manager, corpus_idx) } } diff --git a/afl/src/state/mod.rs b/afl/src/state/mod.rs index 72dc25351a..838da07cc1 100644 --- a/afl/src/state/mod.rs +++ b/afl/src/state/mod.rs @@ -18,7 +18,7 @@ use crate::{ inputs::Input, observers::ObserversTuple, utils::{current_milliseconds, Rand}, - AflError, + Error, }; #[cfg(feature = "std")] @@ -99,7 +99,7 @@ where executor: &mut E, manager: &mut EM, in_dir: &Path, - ) -> Result<(), AflError> + ) -> Result<(), Error> where C: Corpus, E: Executor + HasObservers, @@ -141,7 +141,7 @@ where executor: &mut E, manager: &mut EM, in_dirs: &[PathBuf], - ) -> Result<(), AflError> + ) -> Result<(), Error> where C: Corpus, E: Executor + HasObservers, @@ -268,7 +268,7 @@ where input: &I, observers: &OT, exit_kind: ExitKind, - ) -> Result + ) -> Result where OT: ObserversTuple, { @@ -283,7 +283,7 @@ where input: &I, executor: &mut E, event_mgr: &mut EM, - ) -> Result<(u32, u32), AflError> + ) -> Result<(u32, u32), Error> where E: Executor + HasObservers, OT: ObserversTuple, @@ -311,14 +311,14 @@ where /// Resets all current feedbacks #[inline] - pub fn discard_input(&mut self, input: &I) -> Result<(), AflError> { + pub fn discard_input(&mut self, input: &I) -> Result<(), Error> { // TODO: This could probably be automatic in the feedback somehow? self.feedbacks_mut().discard_metadata_all(&input) } /// Creates a new testcase, appending the metadata from each feedback #[inline] - pub fn input_to_testcase(&mut self, input: I, fitness: u32) -> Result, AflError> { + pub fn input_to_testcase(&mut self, input: I, fitness: u32) -> Result, Error> { let mut testcase = Testcase::new(input); testcase.set_fitness(fitness); self.feedbacks_mut().append_metadata_all(&mut testcase)?; @@ -331,7 +331,7 @@ where &mut self, input: I, fitness: u32, - ) -> Result>, AflError> { + ) -> Result>, Error> { if fitness > 0 { Ok(Some(self.input_to_testcase(input, fitness)?)) } else { @@ -342,7 +342,7 @@ where /// Adds this input to the corpus, if it's intersting #[inline] - pub fn add_if_interesting(&mut self, input: I, fitness: u32) -> Result, AflError> + pub fn add_if_interesting(&mut self, input: I, fitness: u32) -> Result, Error> where C: Corpus, { @@ -357,7 +357,7 @@ where /// Adds this input to the objective corpus, if it's an objective #[inline] - pub fn add_if_objective(&mut self, input: I, fitness: u32) -> Result, AflError> + pub fn add_if_objective(&mut self, input: I, fitness: u32) -> Result, Error> where C: Corpus, { @@ -378,7 +378,7 @@ where input: I, executor: &mut E, manager: &mut EM, - ) -> Result + ) -> Result where E: Executor + HasObservers, OT: ObserversTuple, @@ -420,7 +420,7 @@ where generator: &mut G, manager: &mut EM, num: usize, - ) -> Result<(), AflError> + ) -> Result<(), Error> where G: Generator, C: Corpus, diff --git a/fuzzers/libfuzzer_dummy/src/mod.rs b/fuzzers/libfuzzer_dummy/src/mod.rs index 40364e4ee5..17891b8609 100644 --- a/fuzzers/libfuzzer_dummy/src/mod.rs +++ b/fuzzers/libfuzzer_dummy/src/mod.rs @@ -5,7 +5,7 @@ use std::{path::PathBuf}; use std::io::{self, BufRead}; use afl::{ - bolts::{tuples::tuple_list, shmem::AflShmem}, + bolts::{tuples::tuple_list, shmem::UnixShMem}, corpus::{Corpus, InMemoryCorpus}, events::setup_restarting_mgr, events::{SimpleStats}, @@ -17,7 +17,7 @@ use afl::{ stages::mutational::StdMutationalStage, state::{HasCorpus, State}, utils::StdRand, - AflError, Fuzzer, StdFuzzer, + Error, Fuzzer, StdFuzzer, }; /// The name of the coverage map observer, to find it again in the observer list @@ -53,7 +53,7 @@ pub fn main() { } /// The actual fuzzer -fn fuzz(input: Option>, broker_port: u16) -> Result<(), AflError> { +fn fuzz(input: Option>, broker_port: u16) -> Result<(), Error> { let mut rand = StdRand::new(0); // 'While the stats are state, they are usually used in the broker - which is likely never restarted let stats = SimpleStats::new(|s| println!("{}", s)); @@ -64,7 +64,7 @@ fn fuzz(input: Option>, broker_port: u16) -> Result<(), AflError> { // The restarting state will spawn the same process again as child, then restartet it each time it crashes. let (state_opt, mut restarting_mgr) = - setup_restarting_mgr::<_, _, _, _, AflShmem, _>(stats, broker_port).expect("Failed to setup the restarter".into()); + setup_restarting_mgr::<_, _, _, _, UnixShMem, _>(stats, broker_port).expect("Failed to setup the restarter".into()); let edges_observer = StdMapObserver::new_from_ptr(&NAME_COV_MAP, unsafe { &mut __lafl_edges_map[0] as *mut u8 }, __lafl_max_edges_size as usize); diff --git a/fuzzers/libfuzzer_libpng/src/mod.rs b/fuzzers/libfuzzer_libpng/src/mod.rs index c503d91680..0552338e1e 100644 --- a/fuzzers/libfuzzer_libpng/src/mod.rs +++ b/fuzzers/libfuzzer_libpng/src/mod.rs @@ -4,7 +4,7 @@ use std::{env, path::PathBuf}; use afl::{ - bolts::{serdeany::RegistryBuilder, shmem::AflShmem, tuples::tuple_list}, + bolts::{serdeany::RegistryBuilder, shmem::UnixShMem, tuples::tuple_list}, corpus::{Corpus, InMemoryCorpus, OnDiskCorpus}, events::setup_restarting_mgr, executors::{inprocess::InProcessExecutor, Executor, ExitKind}, @@ -17,7 +17,7 @@ use afl::{ state::{HasCorpus, HasMetadata, State}, stats::SimpleStats, utils::StdRand, - AflError, Fuzzer, StdFuzzer, + Error, Fuzzer, StdFuzzer, }; /// The name of the coverage map observer, to find it again in the observer list @@ -72,14 +72,14 @@ fn fuzz( corpus_dirs: Vec, objective_dir: PathBuf, broker_port: u16, -) -> Result<(), AflError> { +) -> Result<(), Error> { let mut rand = StdRand::new(0); // 'While the stats are state, they are usually used in the broker - which is likely never restarted let stats = SimpleStats::new(|s| println!("{}", s)); // The restarting state will spawn the same process again as child, then restarted it each time it crashes. let (state, mut restarting_mgr) = - setup_restarting_mgr::<_, _, _, _, _, _, AflShmem, _>(stats, broker_port) + setup_restarting_mgr::<_, _, _, _, _, _, UnixShMem, _>(stats, broker_port) .expect("Failed to setup the restarter".into()); // Create an observation channel using the coverage map