fmt
This commit is contained in:
parent
a599a9f998
commit
7236fd9f3c
@ -1242,10 +1242,7 @@ where
|
||||
#[cfg(feature = "std")]
|
||||
/// Launches a thread using a tcp listener socket, on which new clients may connect to this broker
|
||||
/// Does so on the given port.
|
||||
pub fn launch_tcp_listener_on(
|
||||
&mut self,
|
||||
port: u16,
|
||||
) -> Result<thread::JoinHandle<()>, Error> {
|
||||
pub fn launch_tcp_listener_on(&mut self, port: u16) -> 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);
|
||||
@ -1332,11 +1329,7 @@ where
|
||||
|
||||
/// broker broadcast to its own page for all others to read */
|
||||
#[inline]
|
||||
unsafe fn handle_new_msgs<F>(
|
||||
&mut self,
|
||||
client_id: u32,
|
||||
on_new_msg: &mut F,
|
||||
) -> Result<(), Error>
|
||||
unsafe fn handle_new_msgs<F>(&mut self, client_id: u32, on_new_msg: &mut F) -> Result<(), Error>
|
||||
where
|
||||
F: FnMut(u32, Tag, &[u8]) -> Result<LlmpMsgHookResult, Error>,
|
||||
{
|
||||
|
@ -34,8 +34,7 @@ pub trait ShMem: Sized + Debug {
|
||||
}
|
||||
|
||||
/// 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, Error>;
|
||||
fn existing_from_shm_slice(map_str_bytes: &[u8; 20], map_size: usize) -> 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, Error> {
|
||||
@ -324,7 +323,7 @@ pub mod shmem {
|
||||
mod tests {
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use super::{UnixShMem, ShMem};
|
||||
use super::{ShMem, UnixShMem};
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[test]
|
||||
|
@ -54,10 +54,7 @@ where
|
||||
/// Replaces the testcase at the given idx
|
||||
fn replace(&mut self, idx: usize, testcase: Testcase<I>) -> Result<(), Error> {
|
||||
if self.entries_mut().len() < idx {
|
||||
return Err(Error::KeyNotFound(format!(
|
||||
"Index {} out of bounds",
|
||||
idx
|
||||
)));
|
||||
return Err(Error::KeyNotFound(format!("Index {} out of bounds", idx)));
|
||||
}
|
||||
self.entries_mut()[idx] = RefCell::new(testcase);
|
||||
Ok(())
|
||||
|
@ -16,13 +16,13 @@ use crate::{
|
||||
llmp::{self, LlmpClient, LlmpClientDescription, Tag},
|
||||
shmem::ShMem,
|
||||
},
|
||||
executors::{HasObservers, Executor},
|
||||
observers::ObserversTuple,
|
||||
corpus::Corpus,
|
||||
events::{BrokerEventResult, Event, EventManager},
|
||||
executors::ExitKind,
|
||||
executors::{Executor, HasObservers},
|
||||
feedbacks::FeedbacksTuple,
|
||||
inputs::Input,
|
||||
observers::ObserversTuple,
|
||||
state::State,
|
||||
stats::Stats,
|
||||
utils::Rand,
|
||||
@ -264,7 +264,7 @@ where
|
||||
R: Rand,
|
||||
OC: Corpus<I, R>,
|
||||
OFT: FeedbacksTuple<I>,
|
||||
OT: ObserversTuple
|
||||
OT: ObserversTuple,
|
||||
{
|
||||
match event {
|
||||
Event::NewTestcase {
|
||||
@ -329,7 +329,7 @@ where
|
||||
R: Rand,
|
||||
OC: Corpus<I, R>,
|
||||
OFT: FeedbacksTuple<I>,
|
||||
OT: ObserversTuple
|
||||
OT: ObserversTuple,
|
||||
{
|
||||
// TODO: Get around local event copy by moving handle_in_client
|
||||
let mut events = vec![];
|
||||
@ -352,9 +352,9 @@ where
|
||||
}
|
||||
};
|
||||
let count = events.len();
|
||||
events
|
||||
.drain(..)
|
||||
.try_for_each(|(sender_id, event)| self.handle_in_client(state, sender_id, event, executor))?;
|
||||
events.drain(..).try_for_each(|(sender_id, event)| {
|
||||
self.handle_in_client(state, sender_id, event, executor)
|
||||
})?;
|
||||
Ok(count)
|
||||
}
|
||||
|
||||
@ -477,7 +477,7 @@ where
|
||||
R: Rand,
|
||||
OC: Corpus<I, R>,
|
||||
OFT: FeedbacksTuple<I>,
|
||||
OT: ObserversTuple
|
||||
OT: ObserversTuple,
|
||||
{
|
||||
self.llmp_mgr.process(state, executor)
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ use alloc::{string::ToString, vec::Vec};
|
||||
use crate::{
|
||||
corpus::Corpus,
|
||||
events::{BrokerEventResult, Event, EventManager},
|
||||
executors::{HasObservers, Executor},
|
||||
observers::ObserversTuple,
|
||||
executors::{Executor, HasObservers},
|
||||
feedbacks::FeedbacksTuple,
|
||||
inputs::Input,
|
||||
observers::ObserversTuple,
|
||||
state::State,
|
||||
stats::Stats,
|
||||
utils::Rand,
|
||||
@ -45,7 +45,7 @@ where
|
||||
R: Rand,
|
||||
OC: Corpus<I, R>,
|
||||
OFT: FeedbacksTuple<I>,
|
||||
OT: ObserversTuple
|
||||
OT: ObserversTuple,
|
||||
{
|
||||
let count = self.events.len();
|
||||
while self.events.len() > 0 {
|
||||
@ -88,10 +88,7 @@ where
|
||||
}
|
||||
|
||||
// Handle arriving events in the broker
|
||||
fn handle_in_broker(
|
||||
stats: &mut ST,
|
||||
event: &Event<I>,
|
||||
) -> Result<BrokerEventResult, Error> {
|
||||
fn handle_in_broker(stats: &mut ST, event: &Event<I>) -> Result<BrokerEventResult, Error> {
|
||||
match event {
|
||||
Event::NewTestcase {
|
||||
input: _,
|
||||
|
@ -9,9 +9,14 @@ use core::{fmt, marker::PhantomData, time::Duration};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
corpus::Corpus, feedbacks::FeedbacksTuple, inputs::Input, observers::ObserversTuple,
|
||||
executors::{HasObservers, Executor},
|
||||
state::State, utils::Rand, Error,
|
||||
corpus::Corpus,
|
||||
executors::{Executor, HasObservers},
|
||||
feedbacks::FeedbacksTuple,
|
||||
inputs::Input,
|
||||
observers::ObserversTuple,
|
||||
state::State,
|
||||
utils::Rand,
|
||||
Error,
|
||||
};
|
||||
|
||||
/// The log event severity
|
||||
@ -266,7 +271,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use crate::bolts::tuples::{tuple_list};
|
||||
use crate::bolts::tuples::tuple_list;
|
||||
use crate::events::Event;
|
||||
use crate::inputs::bytes::BytesInput;
|
||||
use crate::observers::StdMapObserver;
|
||||
@ -302,7 +307,8 @@ mod tests {
|
||||
time: _,
|
||||
executions: _,
|
||||
} => {
|
||||
let o: tuple_list!(StdMapObserver::<u32>) = postcard::from_bytes(&observers_buf).unwrap();
|
||||
let o: tuple_list!(StdMapObserver::<u32>) =
|
||||
postcard::from_bytes(&observers_buf).unwrap();
|
||||
let test_observer = o.match_name_type::<StdMapObserver<u32>>("test").unwrap();
|
||||
assert_eq!("test", test_observer.name());
|
||||
}
|
||||
|
@ -293,13 +293,16 @@ pub mod unix_signals {
|
||||
if obj_fitness > 0 {
|
||||
if !state
|
||||
.add_if_objective(input.clone(), obj_fitness)
|
||||
.expect("In crash handler objective corpus add failure.".into()).is_none() {
|
||||
.expect("In crash handler objective corpus add failure.".into())
|
||||
.is_none()
|
||||
{
|
||||
mgr.fire(
|
||||
state,
|
||||
Event::Objective {
|
||||
objective_size: state.objective_corpus().count(),
|
||||
},
|
||||
) .expect(&format!("Could not send timeouting input {:?}", input));
|
||||
)
|
||||
.expect(&format!("Could not send timeouting input {:?}", input));
|
||||
}
|
||||
}
|
||||
|
||||
@ -351,13 +354,16 @@ pub mod unix_signals {
|
||||
if obj_fitness > 0 {
|
||||
if !state
|
||||
.add_if_objective(input.clone(), obj_fitness)
|
||||
.expect("In timeout handler objective corpus add failure.".into()).is_none() {
|
||||
.expect("In timeout handler objective corpus add failure.".into())
|
||||
.is_none()
|
||||
{
|
||||
mgr.fire(
|
||||
state,
|
||||
Event::Objective {
|
||||
objective_size: state.objective_corpus().count(),
|
||||
},
|
||||
) .expect(&format!("Could not send timeouting input {:?}", input));
|
||||
)
|
||||
.expect(&format!("Could not send timeouting input {:?}", input));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -891,26 +891,16 @@ pub fn read_tokens_file(f: &str, tokens: &mut Vec<Vec<u8>>) -> Result<u32, Error
|
||||
}
|
||||
let pos_quote = match line.find("\"") {
|
||||
Some(x) => x,
|
||||
_ => {
|
||||
return Err(Error::IllegalArgument(
|
||||
"Illegal line: ".to_owned() + line,
|
||||
))
|
||||
}
|
||||
_ => return Err(Error::IllegalArgument("Illegal line: ".to_owned() + line)),
|
||||
};
|
||||
if line.chars().nth(line.len() - 1) != Some('"') {
|
||||
return Err(Error::IllegalArgument(
|
||||
"Illegal line: ".to_owned() + line,
|
||||
));
|
||||
return Err(Error::IllegalArgument("Illegal line: ".to_owned() + line));
|
||||
}
|
||||
|
||||
// extract item
|
||||
let item = match line.get(pos_quote + 1..line.len() - 1) {
|
||||
Some(x) => x,
|
||||
_ => {
|
||||
return Err(Error::IllegalArgument(
|
||||
"Illegal line: ".to_owned() + line,
|
||||
))
|
||||
}
|
||||
_ => return Err(Error::IllegalArgument("Illegal line: ".to_owned() + line)),
|
||||
};
|
||||
if item.len() == 0 {
|
||||
continue;
|
||||
|
@ -60,7 +60,6 @@ pub trait ObserversTuple:
|
||||
|
||||
//fn for_each(&self, f: fn(&dyn Observer));
|
||||
//fn for_each_mut(&mut self, f: fn(&mut dyn Observer));
|
||||
|
||||
}
|
||||
|
||||
impl ObserversTuple for () {
|
||||
|
@ -260,7 +260,7 @@ where
|
||||
pub fn objective_feedbacks_mut(&mut self) -> &mut OFT {
|
||||
&mut self.objective_feedbacks
|
||||
}
|
||||
|
||||
|
||||
/// Returns the objective corpus
|
||||
#[inline]
|
||||
pub fn objective_corpus(&self) -> &OC {
|
||||
|
@ -43,7 +43,7 @@ impl ClientStats {
|
||||
pub fn update_corpus_size(&mut self, corpus_size: u64) {
|
||||
self.corpus_size = corpus_size;
|
||||
}
|
||||
|
||||
|
||||
/// We got a new information about objective corpus size for this client, insert them.
|
||||
pub fn update_objective_size(&mut self, objective_size: u64) {
|
||||
self.objective_size = objective_size;
|
||||
|
@ -68,11 +68,7 @@ pub fn main() {
|
||||
}
|
||||
|
||||
/// The actual fuzzer
|
||||
fn fuzz(
|
||||
corpus_dirs: Vec<PathBuf>,
|
||||
objective_dir: PathBuf,
|
||||
broker_port: u16,
|
||||
) -> Result<(), Error> {
|
||||
fn fuzz(corpus_dirs: Vec<PathBuf>, objective_dir: PathBuf, broker_port: u16) -> Result<(), Error> {
|
||||
let mut rand = StdRand::new(afl::utils::current_nanos());
|
||||
// 'While the stats are state, they are usually used in the broker - which is likely never restarted
|
||||
let stats = SimpleStats::new(|s| println!("{}", s));
|
||||
|
Loading…
x
Reference in New Issue
Block a user