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