AflError -> Error & AflShmem -> UnixShMem

This commit is contained in:
Andrea Fioraldi 2021-02-15 14:10:54 +01:00
parent 6875f00736
commit 8059a765ed
30 changed files with 322 additions and 322 deletions

View File

@ -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::<AflShmem>::create_attach_to_tcp(port).unwrap();
let mut client = llmp::LlmpClient::<UnixShMem>::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<llmp::LlmpMsgHookResult, AflError> {
) -> Result<llmp::LlmpMsgHookResult, Error> {
match tag {
TAG_SIMPLE_U32_V1 => {
println!(
@ -94,7 +94,7 @@ fn main() {
match mode.as_str() {
"broker" => {
let mut broker = llmp::LlmpBroker::<AflShmem>::new().unwrap();
let mut broker = llmp::LlmpBroker::<UnixShMem>::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::<AflShmem>::create_attach_to_tcp(port).unwrap();
let mut client = llmp::LlmpClient::<UnixShMem>::create_attach_to_tcp(port).unwrap();
let mut counter: u32 = 0;
loop {
counter = counter.wrapping_add(1);

View File

@ -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<Option<u64>, AflError> {
fn msg_offset_from_env(env_name: &str) -> Result<Option<u64>, 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<SH: ShMem>(
map: &mut LlmpSharedMap<SH>,
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::<LlmpPage>() as isize);
@ -202,7 +202,7 @@ unsafe fn llmp_next_msg_ptr_checked<SH: ShMem>(
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<SH: ShMem>(&self, map: &mut LlmpSharedMap<SH>) -> Result<&[u8], AflError> {
pub fn as_slice<SH: ShMem>(&self, map: &mut LlmpSharedMap<SH>) -> 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<Self, AflError> {
pub fn on_port(port: u16) -> Result<Self, Error> {
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<LlmpClientDescription, AflError> {
pub fn describe(&self) -> Result<LlmpClientDescription, Error> {
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<LlmpConnection<SH>, AflError> {
) -> Result<LlmpConnection<SH>, 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<SH> LlmpSender<SH>
where
SH: ShMem,
{
pub fn new(id: u32, keep_pages_forever: bool) -> Result<Self, AflError> {
pub fn new(id: u32, keep_pages_forever: bool) -> Result<Self, Error> {
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<Self, AflError> {
pub fn on_existing_from_env(env_name: &str) -> Result<Self, Error> {
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<u64>,
) -> Result<Self, AflError> {
) -> Result<Self, Error> {
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<LlmpDescription, AflError> {
pub fn describe(&self) -> Result<LlmpDescription, Error> {
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<Self, AflError> {
pub fn on_existing_from_description(description: &LlmpDescription) -> Result<Self, Error> {
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<Self, AflError> {
pub fn on_existing_from_env(env_name: &str) -> Result<Self, Error> {
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<u64>,
) -> Result<Self, AflError> {
) -> Result<Self, Error> {
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<Option<*mut LlmpMsg>, AflError> {
unsafe fn recv(&mut self) -> Result<Option<*mut LlmpMsg>, 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<Option<(u32, u32, &[u8])>, AflError> {
pub fn recv_buf(&mut self) -> Result<Option<(u32, u32, &[u8])>, 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<LlmpDescription, AflError> {
pub fn describe(&self) -> Result<LlmpDescription, Error> {
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<Self, AflError> {
pub fn on_existing_from_description(description: &LlmpDescription) -> Result<Self, Error> {
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<u64, AflError> {
pub fn msg_to_offset(&self, msg: *const LlmpMsg) -> Result<u64, Error> {
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::<LlmpPage>();
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<Self, AflError> {
pub fn new() -> Result<Self, Error> {
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<F>(&mut self, on_new_msg: &mut F) -> Result<(), AflError>
pub fn once<F>(&mut self, on_new_msg: &mut F) -> Result<(), Error>
where
F: FnMut(u32, Tag, &[u8]) -> Result<LlmpMsgHookResult, AflError>,
F: FnMut(u32, Tag, &[u8]) -> Result<LlmpMsgHookResult, Error>,
{
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<F>(&mut self, on_new_msg: &mut F, sleep_time: Option<Duration>) -> !
where
F: FnMut(u32, Tag, &[u8]) -> Result<LlmpMsgHookResult, AflError>,
F: FnMut(u32, Tag, &[u8]) -> Result<LlmpMsgHookResult, Error>,
{
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<thread::JoinHandle<()>, AflError> {
) -> Result<thread::JoinHandle<()>, 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<thread::JoinHandle<()>, AflError> {
) -> Result<thread::JoinHandle<()>, 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<LlmpMsgHookResult, AflError>,
F: FnMut(u32, Tag, &[u8]) -> Result<LlmpMsgHookResult, Error>,
{
let mut next_id = self.llmp_clients.len() as u32;
@ -1365,7 +1365,7 @@ where
size_of::<LlmpPayloadSharedMapInfo>()
);
#[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::<LlmpPayloadSharedMapInfo>()
)));
@ -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<u64>,
current_broker_map: SH,
last_msg_recvd_offset: Option<u64>,
) -> Result<Self, AflError> {
) -> Result<Self, Error> {
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<Self, AflError> {
pub fn on_existing_from_env(env_name: &str) -> Result<Self, Error> {
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<LlmpClientDescription, AflError> {
fn describe(&self) -> Result<LlmpClientDescription, Error> {
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<Self, AflError> {
) -> Result<Self, Error> {
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<SH>) -> Result<Self, AflError> {
pub fn new(initial_broker_map: LlmpSharedMap<SH>) -> Result<Self, Error> {
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<Option<*mut LlmpMsg>, AflError> {
pub unsafe fn recv(&mut self) -> Result<Option<*mut LlmpMsg>, 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<Option<(u32, u32, &[u8])>, AflError> {
pub fn recv_buf(&mut self) -> Result<Option<(u32, u32, &[u8])>, 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<Self, AflError> {
pub fn create_using_env(env_var: &str) -> Result<Self, Error> {
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<Self, AflError> {
pub fn create_attach_to_tcp(port: u16) -> Result<Self, Error> {
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::<AflShmem>::on_port(1337).unwrap() {
let mut broker = match LlmpConnection::<UnixShMem>::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::<AflShmem>::on_port(1337).unwrap() {
let mut client = match LlmpConnection::<UnixShMem>::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::<AflShmem>::on_existing_from_env("_ENV_TEST").unwrap();
client = LlmpClient::<UnixShMem>::on_existing_from_env("_ENV_TEST").unwrap();
client.send_buf(tag, &arr).unwrap();

View File

@ -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<dyn $trait_name>) -> Result<(), AflError>,
) -> Result<(), AflError> {
func: fn(&TypeId, &Box<dyn $trait_name>) -> 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<dyn $trait_name>) -> Result<(), AflError>,
) -> Result<(), AflError> {
func: fn(&TypeId, &mut Box<dyn $trait_name>) -> Result<(), Error>,
) -> Result<(), Error> {
for (id, h) in self.map.iter_mut() {
for x in h.values_mut() {
func(&pack_type_id(*id), x)?;

View File

@ -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<Self, AflError>;
fn new_map(map_size: usize) -> Result<Self, Error>;
/// Creates a new reference to the same map
fn clone_ref(old_ref: &Self) -> Result<Self, AflError> {
fn clone_ref(old_ref: &Self) -> Result<Self, Error> {
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<Self, AflError>;
-> Result<Self, Error>;
/// Initialize from a shm_str with fixed len of 20
fn existing_from_shm_str(shm_str: &str, map_size: usize) -> Result<Self, AflError> {
fn existing_from_shm_str(shm_str: &str, map_size: usize) -> Result<Self, Error> {
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<Self, AflError> {
fn existing_from_description(description: &ShMemDescription) -> Result<Self, Error> {
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<Self, AflError> {
fn existing_from_env(env_name: &str) -> Result<Self, Error> {
let map_shm_str = env::var(env_name)?;
let map_size = str::parse::<usize>(&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<Self, AflError> {
) -> Result<Self, Error> {
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<Self, AflError> {
fn new_map(map_size: usize) -> Result<Self, Error> {
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<Self, AflError> {
impl UnixShMem {
pub fn from_str(shm_str: &CStr, map_size: usize) -> Result<Self, Error> {
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<Self, AflError> {
pub fn new(map_size: usize) -> Result<Self, Error> {
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,

View File

@ -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<Testcase<I>>, usize), AflError> {
fn next(&mut self, rand: &mut R) -> Result<(&RefCell<Testcase<I>>, 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;

View File

@ -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<I>
@ -52,9 +52,9 @@ where
}
/// Replaces the testcase at the given idx
fn replace(&mut self, idx: usize, testcase: Testcase<I>) -> Result<(), AflError> {
fn replace(&mut self, idx: usize, testcase: Testcase<I>) -> 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<Testcase<I>>, usize), AflError> {
fn random_entry(&self, rand: &mut R) -> Result<(&RefCell<Testcase<I>>, 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<Testcase<I>>, usize), AflError>;
fn next(&mut self, rand: &mut R) -> Result<(&RefCell<Testcase<I>>, usize), Error>;
/// Returns the testacase we currently use
fn current_testcase(&self) -> (&RefCell<Testcase<I>>, usize);

View File

@ -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<Testcase<I>>, usize), AflError> {
fn next(&mut self, rand: &mut R) -> Result<(&RefCell<Testcase<I>>, 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;

View File

@ -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<Testcase<I>>, usize), AflError> {
fn random_entry(&self, rand: &mut R) -> Result<(&RefCell<Testcase<I>>, 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<Testcase<I>>, usize), AflError> {
fn next(&mut self, _rand: &mut R) -> Result<(&RefCell<Testcase<I>>, 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?

View File

@ -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<bool, AflError> {
pub fn store_input(&mut self) -> Result<bool, Error> {
let fname;
match self.filename() {
Some(f) => {

View File

@ -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<I, ST> LlmpEventManager<I, AflShmem, ST>
impl<I, ST> LlmpEventManager<I, UnixShMem, ST>
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<Self, AflError> {
pub fn new_on_port_std(stats: ST, port: u16) -> Result<Self, Error> {
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<Self, AflError> {
pub fn existing_client_from_env_std(env_name: &str) -> Result<Self, Error> {
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<Self, AflError> {
pub fn new_on_port(stats: ST, port: u16) -> Result<Self, Error> {
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<Self, AflError> {
pub fn existing_client_from_env(env_name: &str) -> Result<Self, Error> {
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<LlmpClientDescription, AflError> {
pub fn describe(&self) -> Result<LlmpClientDescription, Error> {
self.llmp.describe()
}
/// Create an existing client from description
pub fn existing_client_from_description(
description: &LlmpClientDescription,
) -> Result<Self, AflError> {
) -> Result<Self, Error> {
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<I>,
) -> Result<BrokerEventResult, AflError> {
) -> Result<BrokerEventResult, Error> {
match &event {
Event::NewTestcase {
input: _,
@ -257,7 +257,7 @@ where
state: &mut State<C, FT, I, OC, OFT, R>,
_sender_id: u32,
event: Event<I>,
) -> Result<(), AflError>
) -> Result<(), Error>
where
C: Corpus<I, R>,
FT: FeedbacksTuple<I>,
@ -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<C, FT, OC, OFT, R>(
&mut self,
state: &mut State<C, FT, I, OC, OFT, R>,
) -> Result<usize, AflError>
) -> Result<usize, Error>
where
C: Corpus<I, R>,
FT: FeedbacksTuple<I>,
@ -352,7 +352,7 @@ where
&mut self,
_state: &mut State<C, FT, I, OC, OFT, R>,
event: Event<I>,
) -> Result<(), AflError>
) -> Result<(), Error>
where
C: Corpus<I, R>,
FT: FeedbacksTuple<I>,
@ -373,7 +373,7 @@ where
pub fn serialize_state_mgr<C, FT, I, OC, OFT, R, SH, ST>(
state: &State<C, FT, I, OC, OFT, R>,
mgr: &LlmpEventManager<I, SH, ST>,
) -> Result<Vec<u8>, AflError>
) -> Result<Vec<u8>, Error>
where
C: Corpus<I, R>,
FT: FeedbacksTuple<I>,
@ -390,7 +390,7 @@ where
/// Deserialize the state and corpus tuple, previously serialized with `serialize_state_corpus(...)`
pub fn deserialize_state_mgr<C, FT, I, OC, OFT, R, SH, ST>(
state_corpus_serialized: &[u8],
) -> Result<(State<C, FT, I, OC, OFT, R>, LlmpEventManager<I, SH, ST>), AflError>
) -> Result<(State<C, FT, I, OC, OFT, R>, LlmpEventManager<I, SH, ST>), Error>
where
C: Corpus<I, R>,
FT: FeedbacksTuple<I>,
@ -440,7 +440,7 @@ where
fn on_restart<C, FT, OC, OFT, R>(
&mut self,
state: &mut State<C, FT, I, OC, OFT, R>,
) -> Result<(), AflError>
) -> Result<(), Error>
where
C: Corpus<I, R>,
FT: FeedbacksTuple<I>,
@ -458,7 +458,7 @@ where
fn process<C, FT, OC, OFT, R>(
&mut self,
state: &mut State<C, FT, I, OC, OFT, R>,
) -> Result<usize, AflError>
) -> Result<usize, Error>
where
C: Corpus<I, R>,
FT: FeedbacksTuple<I>,
@ -473,7 +473,7 @@ where
&mut self,
state: &mut State<C, FT, I, OC, OFT, R>,
event: Event<I>,
) -> Result<(), AflError>
) -> Result<(), Error>
where
C: Corpus<I, R>,
FT: FeedbacksTuple<I>,
@ -526,7 +526,7 @@ pub fn setup_restarting_mgr<I, C, FT, OC, OFT, R, SH, ST>(
Option<State<C, FT, I, OC, OFT, R>>,
LlmpRestartingEventManager<I, SH, ST>,
),
AflError,
Error,
>
where
I: Input,

View File

@ -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<C, FT, OC, OFT, R>(
&mut self,
state: &mut State<C, FT, I, OC, OFT, R>,
) -> Result<usize, AflError>
) -> Result<usize, Error>
where
C: Corpus<I, R>,
FT: FeedbacksTuple<I>,
@ -54,7 +54,7 @@ where
&mut self,
_state: &mut State<C, FT, I, OC, OFT, R>,
event: Event<I>,
) -> Result<(), AflError>
) -> Result<(), Error>
where
C: Corpus<I, R>,
FT: FeedbacksTuple<I>,
@ -87,7 +87,7 @@ where
stats: &mut ST,
_sender_id: u32,
event: &Event<I>,
) -> Result<BrokerEventResult, AflError> {
) -> Result<BrokerEventResult, Error> {
match event {
Event::NewTestcase {
input: _,
@ -137,7 +137,7 @@ where
_state: &mut State<C, FT, I, OC, OFT, R>,
_sender_id: u32,
event: Event<I>,
) -> Result<(), AflError>
) -> Result<(), Error>
where
C: Corpus<I, R>,
FT: FeedbacksTuple<I>,
@ -146,7 +146,7 @@ where
OFT: FeedbacksTuple<I>,
{
match event {
_ => Err(AflError::Unknown(format!(
_ => Err(Error::Unknown(format!(
"Received illegal message that message should not have arrived: {:?}.",
event
))),

View File

@ -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<BrokerEventResult, AflError>;
fn handle_in_broker(&self) -> Result<BrokerEventResult, Error>;
/// 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<I>) -> Result<(), AflError>;
//fn fire<'a>(&mut self, event: Event<I>) -> Result<(), Error>;
/// Lookup for incoming events and process them.
/// Return the number of processes events or an error
fn process<C, FT, OC, OFT, R>(
&mut self,
state: &mut State<C, FT, I, OC, OFT, R>,
) -> Result<usize, AflError>
) -> Result<usize, Error>
where
C: Corpus<I, R>,
FT: FeedbacksTuple<I>,
@ -174,7 +174,7 @@ where
OFT: FeedbacksTuple<I>;
/// Serialize all observers for this type and manager
fn serialize_observers<OT>(&mut self, observers: &OT) -> Result<Vec<u8>, AflError>
fn serialize_observers<OT>(&mut self, observers: &OT) -> Result<Vec<u8>, Error>
where
OT: ObserversTuple,
{
@ -182,7 +182,7 @@ where
}
/// Deserialize all observers for this type and manager
fn deserialize_observers<OT>(&mut self, observers_buf: &[u8]) -> Result<OT, AflError>
fn deserialize_observers<OT>(&mut self, observers_buf: &[u8]) -> Result<OT, Error>
where
OT: ObserversTuple,
{
@ -194,7 +194,7 @@ where
fn on_restart<C, FT, OC, OFT, R>(
&mut self,
_state: &mut State<C, FT, I, OC, OFT, R>,
) -> Result<(), AflError>
) -> Result<(), Error>
where
C: Corpus<I, R>,
FT: FeedbacksTuple<I>,
@ -214,7 +214,7 @@ where
&mut self,
_state: &mut State<C, FT, I, OC, OFT, R>,
event: Event<I>,
) -> Result<(), AflError>
) -> Result<(), Error>
where
C: Corpus<I, R>,
FT: FeedbacksTuple<I>,
@ -235,7 +235,7 @@ where
fn process<C, FT, OC, OFT, R>(
&mut self,
_state: &mut State<C, FT, I, OC, OFT, R>,
) -> Result<usize, AflError>
) -> Result<usize, Error>
where
C: Corpus<I, R>,
FT: FeedbacksTuple<I>,
@ -250,7 +250,7 @@ where
&mut self,
_state: &mut State<C, FT, I, OC, OFT, R>,
_event: Event<I>,
) -> Result<(), AflError>
) -> Result<(), Error>
where
C: Corpus<I, R>,
FT: FeedbacksTuple<I>,

View File

@ -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<C, FT, I, OC, OFT, R>,
_event_mgr: &mut EM,
_input: &I,
) -> Result<(), AflError>
) -> Result<(), Error>
where
R: Rand,
FT: FeedbacksTuple<I>,
@ -87,7 +87,7 @@ where
_state: &State<C, FT, I, OC, OFT, R>,
_event_mgr: &mut EM,
_input: &I,
) -> Result<(), AflError>
) -> Result<(), Error>
where
R: Rand,
FT: FeedbacksTuple<I>,
@ -105,7 +105,7 @@ where
}
#[inline]
fn run_target(&mut self, input: &I) -> Result<ExitKind, AflError> {
fn run_target(&mut self, input: &I) -> Result<ExitKind, Error> {
let bytes = input.target_bytes();
let ret = (self.harness_fn)(self, bytes.as_slice());
Ok(ret)

View File

@ -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<I> Executor<I> for NopExecutor<I>
where
I: Input + HasTargetBytes,
{
fn run_target(&mut self, input: &I) -> Result<ExitKind, AflError> {
fn run_target(&mut self, input: &I) -> Result<ExitKind, Error> {
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<C, FT, I, OC, OFT, R>,
_event_mgr: &mut EM,
_input: &I,
) -> Result<(), AflError>
) -> Result<(), Error>
where
R: Rand,
FT: FeedbacksTuple<I>,
@ -108,7 +108,7 @@ where
_state: &State<C, FT, I, OC, OFT, R>,
_event_mgr: &mut EM,
_input: &I,
) -> Result<(), AflError>
) -> Result<(), Error>
where
R: Rand,
FT: FeedbacksTuple<I>,
@ -121,7 +121,7 @@ where
}
/// Instruct the target about the input and run
fn run_target(&mut self, input: &I) -> Result<ExitKind, AflError>;
fn run_target(&mut self, input: &I) -> Result<ExitKind, Error>;
}
pub trait ExecutorsTuple<I>: MatchType + MatchNameAndType

View File

@ -12,7 +12,7 @@ use crate::{
feedbacks::Feedback,
inputs::Input,
observers::{MapObserver, Observer, ObserversTuple},
AflError,
Error,
};
pub type MaxMapFeedback<T, O> = MapFeedback<T, MaxReducer<T>, O>;
@ -108,7 +108,7 @@ where
_input: &I,
observers: &OT,
_exit_kind: ExitKind,
) -> Result<u32, AflError> {
) -> Result<u32, Error> {
let mut interesting = 0;
// TODO optimize
let observer = observers.match_name_type::<O>(&self.name).unwrap();
@ -245,7 +245,7 @@ where
O: MapObserver<T>,
I: Input,
{
fn is_interesting(&mut self, _input: &I) -> Result<u32, AflError> {
fn is_interesting(&mut self, _input: &I) -> Result<u32, Error> {
let mut interesting = 0;
// TODO optimize
@ -266,14 +266,14 @@ where
Ok(interesting)
}
fn append_metadata(&mut self, testcase: &mut Testcase<I>) -> Result<(), AflError> {
fn append_metadata(&mut self, testcase: &mut Testcase<I>) -> 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(())
}

View File

@ -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<u32, AflError>;
) -> Result<u32, Error>;
/// Append to the testcase the generated metadata in case of a new corpus item
#[inline]
fn append_metadata(&mut self, _testcase: &mut Testcase<I>) -> Result<(), AflError> {
fn append_metadata(&mut self, _testcase: &mut Testcase<I>) -> 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<Vec<u8>, AflError> {
fn serialize_state(&mut self) -> Result<Vec<u8>, 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<u32, AflError>;
) -> Result<u32, Error>;
/// Write metadata for this testcase
fn append_metadata_all(&mut self, testcase: &mut Testcase<I>) -> Result<(), AflError>;
fn append_metadata_all(&mut self, testcase: &mut Testcase<I>) -> 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<u32, AflError> {
) -> Result<u32, Error> {
Ok(0)
}
#[inline]
fn append_metadata_all(&mut self, _testcase: &mut Testcase<I>) -> Result<(), AflError> {
fn append_metadata_all(&mut self, _testcase: &mut Testcase<I>) -> 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<u32, AflError> {
) -> Result<u32, Error> {
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<I>) -> Result<(), AflError> {
fn append_metadata_all(&mut self, testcase: &mut Testcase<I>) -> 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<u32, AflError> {
) -> Result<u32, Error> {
if exit_kind == ExitKind::Crash {
Ok(1)
} else {

View File

@ -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<I, AflError>;
fn generate(&mut self, rand: &mut R) -> Result<I, Error>;
/// Generate a new dummy input
fn generate_dummy(&self) -> I;
@ -39,7 +39,7 @@ impl<R> Generator<BytesInput, R> for RandBytesGenerator<R>
where
R: Rand,
{
fn generate(&mut self, rand: &mut R) -> Result<BytesInput, AflError> {
fn generate(&mut self, rand: &mut R) -> Result<BytesInput, Error> {
let mut size = rand.below(self.max_size as u64);
if size == 0 {
size = 1;
@ -78,7 +78,7 @@ impl<R> Generator<BytesInput, R> for RandPrintablesGenerator<R>
where
R: Rand,
{
fn generate(&mut self, rand: &mut R) -> Result<BytesInput, AflError> {
fn generate(&mut self, rand: &mut R) -> Result<BytesInput, Error> {
let mut size = rand.below(self.max_size as u64);
if size == 0 {
size = 1;

View File

@ -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<P>(&self, path: P) -> Result<(), AflError>
fn to_file<P>(&self, path: P) -> Result<(), Error>
where
P: AsRef<Path>,
{
@ -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<P>(&self, _path: P) -> Result<(), AflError>
fn to_file<P>(&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<P>(path: P) -> Result<Self, AflError>
fn from_file<P>(path: P) -> Result<Self, Error>
where
P: AsRef<Path>,
{
@ -51,9 +51,9 @@ where {
/// Write this input to the file
#[cfg(not(feature = "std"))]
fn from_file<P>(_path: P) -> Result<Self, AflError>
fn from_file<P>(_path: P) -> Result<Self, Error>
where {
Err(AflError::NotImplemented("Not suppored in no_std".into()))
Err(Error::NotImplemented("Not suppored in no_std".into()))
}
}

View File

@ -62,7 +62,7 @@ where
executor: &mut E,
state: &mut State<C, FT, I, OC, OFT, R>,
manager: &mut EM,
) -> Result<usize, AflError> {
) -> Result<usize, Error> {
let (_, idx) = state.corpus_mut().next(rand)?;
self.stages_mut()
@ -78,7 +78,7 @@ where
executor: &mut E,
state: &mut State<C, FT, I, OC, OFT, R>,
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<postcard::Error> for AflError {
impl From<postcard::Error> for Error {
fn from(err: postcard::Error) -> Self {
Self::Serialize(format!("{:?}", err))
}
@ -216,28 +216,28 @@ impl From<postcard::Error> for AflError {
/// Create an AFL Error from io Error
#[cfg(feature = "std")]
impl From<io::Error> for AflError {
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Self::File(err)
}
}
#[cfg(feature = "std")]
impl From<FromUtf8Error> for AflError {
impl From<FromUtf8Error> for Error {
fn from(err: FromUtf8Error) -> Self {
Self::Unknown(format!("Could not convert byte to utf-8: {:?}", err))
}
}
#[cfg(feature = "std")]
impl From<VarError> for AflError {
impl From<VarError> for Error {
fn from(err: VarError) -> Self {
Self::Empty(format!("Could not get env var: {:?}", err))
}
}
#[cfg(feature = "std")]
impl From<ParseIntError> for AflError {
impl From<ParseIntError> for Error {
fn from(err: ParseIntError) -> Self {
Self::Unknown(format!("Failed to parse Int: {:?}", err))
}

View File

@ -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(())
}
}

View File

@ -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<I, M, R, S> =
fn(&mut M, &mut R, &mut S, &mut I) -> Result<MutationResult, AflError>;
fn(&mut M, &mut R, &mut S, &mut I) -> Result<MutationResult, Error>;
pub trait ComposedByMutations<C, I, R, S>
where
@ -131,7 +131,7 @@ pub fn mutation_bitflip<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,
@ -153,7 +153,7 @@ pub fn mutation_byteflip<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,
@ -175,7 +175,7 @@ pub fn mutation_byteinc<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,
@ -198,7 +198,7 @@ pub fn mutation_bytedec<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,
@ -221,7 +221,7 @@ pub fn mutation_byteneg<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,
@ -243,7 +243,7 @@ pub fn mutation_byterand<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,
@ -265,7 +265,7 @@ pub fn mutation_byteadd<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,
@ -292,7 +292,7 @@ pub fn mutation_wordadd<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,
@ -321,7 +321,7 @@ pub fn mutation_dwordadd<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,
@ -350,7 +350,7 @@ pub fn mutation_qwordadd<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,
@ -379,7 +379,7 @@ pub fn mutation_byteinteresting<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,
@ -402,7 +402,7 @@ pub fn mutation_wordinteresting<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,
@ -430,7 +430,7 @@ pub fn mutation_dwordinteresting<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,
@ -458,7 +458,7 @@ pub fn mutation_bytesdelete<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,
@ -481,7 +481,7 @@ pub fn mutation_bytesexpand<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
M: HasMaxSize,
I: Input + HasBytesVec,
@ -510,7 +510,7 @@ pub fn mutation_bytesinsert<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
M: HasMaxSize,
I: Input + HasBytesVec,
@ -542,7 +542,7 @@ pub fn mutation_bytesrandinsert<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
M: HasMaxSize,
I: Input + HasBytesVec,
@ -574,7 +574,7 @@ pub fn mutation_bytesset<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,
@ -598,7 +598,7 @@ pub fn mutation_bytesrandset<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,
@ -622,7 +622,7 @@ pub fn mutation_bytescopy<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,
@ -646,7 +646,7 @@ pub fn mutation_bytesswap<I, M, R, S>(
rand: &mut R,
_: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,
@ -673,7 +673,7 @@ pub fn mutation_crossover_insert<C, I, M, R, S>(
rand: &mut R,
state: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
M: HasMaxSize,
C: Corpus<I, R>,
@ -722,7 +722,7 @@ pub fn mutation_crossover_replace<C, I, M, R, S>(
rand: &mut R,
state: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
C: Corpus<I, R>,
I: Input + HasBytesVec,
@ -776,7 +776,7 @@ pub fn mutation_splice<C, I, M, R, S>(
rand: &mut R,
state: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
C: Corpus<I, R>,
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<u8, AflError> {
fn from_hex(hex: u8) -> Result<u8, Error> {
if hex >= 48 && hex <= 57 {
return Ok(hex - 48);
}
@ -824,11 +824,11 @@ fn from_hex(hex: u8) -> Result<u8, AflError> {
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<Vec<u8>, AflError> {
pub fn str_decode(item: &str) -> Result<Vec<u8>, Error> {
let mut token: Vec<u8> = Vec::new();
let item: Vec<u8> = item.as_bytes().to_vec();
let backslash: u8 = 92; // '\\'
@ -872,7 +872,7 @@ pub fn add_token(tokens: &mut Vec<Vec<u8>>, token: &Vec<u8>) -> 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<Vec<u8>>) -> Result<u32, AflError> {
pub fn read_tokens_file(f: &str, tokens: &mut Vec<Vec<u8>>) -> Result<u32, Error> {
let mut entries = 0;
println!("Loading tokens file {:?} ...", &f);
@ -892,13 +892,13 @@ pub fn read_tokens_file(f: &str, tokens: &mut Vec<Vec<u8>>) -> Result<u32, AflEr
let pos_quote = match line.find("\"") {
Some(x) => 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<Vec<u8>>) -> Result<u32, AflEr
let item = match line.get(pos_quote + 1..line.len() - 1) {
Some(x) => 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<Vec<u8>>) -> Result<u32, AflEr
let token: Vec<u8> = match str_decode(item) {
Ok(val) => val,
Err(_) => {
return Err(AflError::IllegalArgument(
return Err(Error::IllegalArgument(
"Illegal line (hex decoding): ".to_owned() + line,
))
}

View File

@ -7,7 +7,7 @@ use crate::{
mutators::{Corpus, *},
state::{HasCorpus, HasMetadata},
utils::Rand,
AflError,
Error,
};
pub trait ScheduledMutator<C, I, R, S>:
@ -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 {

View File

@ -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<I, M, R, S>(
rand: &mut R,
state: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
M: HasMaxSize,
I: Input + HasBytesVec,
@ -89,7 +89,7 @@ pub fn mutation_tokenreplace<I, M, R, S>(
rand: &mut R,
state: &mut S,
input: &mut I,
) -> Result<MutationResult, AflError>
) -> Result<MutationResult, Error>
where
I: Input + HasBytesVec,
R: Rand,

View File

@ -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<u8>,
{
#[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];
}

View File

@ -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<Vec<u8>, AflError> {
fn serialize_state(&mut self) -> Result<Vec<u8>, 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<Vec<u8>, AflError> {
fn serialize(&self) -> Result<Vec<u8>, Error> {
Ok(postcard::to_allocvec(&self)?)
}
/// Deserilaize
fn deserialize(&self, serialized: &[u8]) -> Result<Self, AflError> {
fn deserialize(&self, serialized: &[u8]) -> Result<Self, Error> {
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(())
}

View File

@ -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<C, FT, I, OC, OFT, R>,
manager: &mut EM,
corpus_idx: usize,
) -> Result<(), AflError>;
) -> Result<(), Error>;
}
pub trait StagesTuple<C, E, EM, FT, I, OC, OFT, OT, R>
@ -58,7 +58,7 @@ where
state: &mut State<C, FT, I, OC, OFT, R>,
manager: &mut EM,
corpus_idx: usize,
) -> Result<(), AflError>;
) -> Result<(), Error>;
fn for_each(&self, f: fn(&dyn Stage<C, E, EM, FT, I, OC, OFT, OT, R>));
fn for_each_mut(&mut self, f: fn(&mut dyn Stage<C, E, EM, FT, I, OC, OFT, OT, R>));
}
@ -82,7 +82,7 @@ where
_state: &mut State<C, FT, I, OC, OFT, R>,
_manager: &mut EM,
_corpus_idx: usize,
) -> Result<(), AflError> {
) -> Result<(), Error> {
Ok(())
}
fn for_each(&self, _f: fn(&dyn Stage<C, E, EM, FT, I, OC, OFT, OT, R>)) {}
@ -111,7 +111,7 @@ where
state: &mut State<C, FT, I, OC, OFT, R>,
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)

View File

@ -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<C, FT, I, OC, OFT, R>,
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<C, FT, I, OC, OFT, R>,
manager: &mut EM,
corpus_idx: usize,
) -> Result<(), AflError> {
) -> Result<(), Error> {
self.perform_mutational(rand, executor, state, manager, corpus_idx)
}
}

View File

@ -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<BytesInput, R>,
E: Executor<BytesInput> + HasObservers<OT>,
@ -141,7 +141,7 @@ where
executor: &mut E,
manager: &mut EM,
in_dirs: &[PathBuf],
) -> Result<(), AflError>
) -> Result<(), Error>
where
C: Corpus<BytesInput, R>,
E: Executor<BytesInput> + HasObservers<OT>,
@ -268,7 +268,7 @@ where
input: &I,
observers: &OT,
exit_kind: ExitKind,
) -> Result<u32, AflError>
) -> Result<u32, Error>
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<I> + HasObservers<OT>,
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<Testcase<I>, AflError> {
pub fn input_to_testcase(&mut self, input: I, fitness: u32) -> Result<Testcase<I>, 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<Option<Testcase<I>>, AflError> {
) -> Result<Option<Testcase<I>>, 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<Option<usize>, AflError>
pub fn add_if_interesting(&mut self, input: I, fitness: u32) -> Result<Option<usize>, Error>
where
C: Corpus<I, R>,
{
@ -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<Option<usize>, AflError>
pub fn add_if_objective(&mut self, input: I, fitness: u32) -> Result<Option<usize>, Error>
where
C: Corpus<I, R>,
{
@ -378,7 +378,7 @@ where
input: I,
executor: &mut E,
manager: &mut EM,
) -> Result<u32, AflError>
) -> Result<u32, Error>
where
E: Executor<I> + HasObservers<OT>,
OT: ObserversTuple,
@ -420,7 +420,7 @@ where
generator: &mut G,
manager: &mut EM,
num: usize,
) -> Result<(), AflError>
) -> Result<(), Error>
where
G: Generator<I, R>,
C: Corpus<I, R>,

View File

@ -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<Vec<PathBuf>>, broker_port: u16) -> Result<(), AflError> {
fn fuzz(input: Option<Vec<PathBuf>>, 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<Vec<PathBuf>>, 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);

View File

@ -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<PathBuf>,
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