testcases fixed, no_std fixes

This commit is contained in:
Dominik Maier 2021-02-25 17:17:55 +01:00
parent 705196fe32
commit 0134b74a39
9 changed files with 45 additions and 39 deletions

View File

@ -32,11 +32,11 @@ where
pub struct MinimizerCorpusScheduler<C, CS, F, I, S> pub struct MinimizerCorpusScheduler<C, CS, F, I, S>
where where
CS: CorpusScheduler<I, S>, CS: CorpusScheduler<I, S>,
F: FavFactor<I>, F: FavFactor<I>,
I: Input, I: Input,
S: HasCorpus<C, I>, S: HasCorpus<C, I>,
C: Corpus<I> C: Corpus<I>,
{ {
base: CS, base: CS,
phantom: PhantomData<(C, F, I, S)>, phantom: PhantomData<(C, F, I, S)>,
@ -44,11 +44,11 @@ C: Corpus<I>
impl<C, CS, F, I, S> CorpusScheduler<I, S> for MinimizerCorpusScheduler<C, CS, F, I, S> impl<C, CS, F, I, S> CorpusScheduler<I, S> for MinimizerCorpusScheduler<C, CS, F, I, S>
where where
CS: CorpusScheduler<I, S>, CS: CorpusScheduler<I, S>,
F: FavFactor<I>, F: FavFactor<I>,
I: Input, I: Input,
S: HasCorpus<C, I>, S: HasCorpus<C, I>,
C: Corpus<I> C: Corpus<I>,
{ {
/// Add an entry to the corpus and return its index /// Add an entry to the corpus and return its index
fn on_add(&self, state: &mut S, idx: usize) -> Result<(), Error> { fn on_add(&self, state: &mut S, idx: usize) -> Result<(), Error> {
@ -83,7 +83,7 @@ where
F: FavFactor<I>, F: FavFactor<I>,
I: Input, I: Input,
S: HasCorpus<C, I>, S: HasCorpus<C, I>,
C: Corpus<I> C: Corpus<I>,
{ {
/*pub fn update_score(&self, state: &mut S, idx: usize) -> Result<(), Error> { /*pub fn update_score(&self, state: &mut S, idx: usize) -> Result<(), Error> {
let entry = state.corpus().get(idx)?.borrow_mut(); let entry = state.corpus().get(idx)?.borrow_mut();
@ -94,7 +94,7 @@ where
continue continue
} }
} }
let _ = self.top_rated.insert(elem, idx); let _ = self.top_rated.insert(elem, idx);
} }
}*/ }*/

View File

@ -15,8 +15,9 @@ pub mod queue;
pub use queue::QueueCorpusScheduler; pub use queue::QueueCorpusScheduler;
pub mod minset; pub mod minset;
use core::cell::RefCell;
use core::marker::PhantomData; use alloc::borrow::ToOwned;
use core::{cell::RefCell, marker::PhantomData};
use crate::{ use crate::{
inputs::Input, inputs::Input,

View File

@ -255,7 +255,7 @@ where
fn handle_in_client<E, OT>( fn handle_in_client<E, OT>(
&mut self, &mut self,
state: &mut S, state: &mut S,
sender_id: u32, _sender_id: u32,
event: Event<I>, event: Event<I>,
_executor: &mut E, _executor: &mut E,
) -> Result<(), Error> ) -> Result<(), Error>
@ -275,7 +275,7 @@ where
// TODO: here u should match client_config, if equal to the current one do not re-execute // TODO: here u should match client_config, if equal to the current one do not re-execute
// we need to pass engine to process() too, TODO // we need to pass engine to process() too, TODO
#[cfg(feature = "std")] #[cfg(feature = "std")]
println!("Received new Testcase from {}", sender_id); println!("Received new Testcase from {}", _sender_id);
let observers: OT = postcard::from_bytes(&observers_buf)?; let observers: OT = postcard::from_bytes(&observers_buf)?;
// TODO include ExitKind in NewTestcase // TODO include ExitKind in NewTestcase

View File

@ -1,8 +1,6 @@
use alloc::{string::ToString, vec::Vec}; use alloc::{string::ToString, vec::Vec};
use core::marker::PhantomData; use core::marker::PhantomData;
#[cfg(feature = "std")]
#[cfg(unix)]
use crate::{ use crate::{
events::{BrokerEventResult, Event, EventManager}, events::{BrokerEventResult, Event, EventManager},
executors::{Executor, HasObservers}, executors::{Executor, HasObservers},

View File

@ -5,6 +5,7 @@ pub use logger::*;
pub mod llmp; pub mod llmp;
pub use llmp::*; pub use llmp::*;
use alloc::{string::String, vec::Vec};
use core::{fmt, marker::PhantomData, time::Duration}; use core::{fmt, marker::PhantomData, time::Duration};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -218,11 +219,15 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::bolts::tuples::tuple_list; use tuple_list::tuple_list_type;
use crate::events::Event;
use crate::inputs::bytes::BytesInput; use crate::{
use crate::observers::StdMapObserver; bolts::tuples::{tuple_list, Named},
use crate::utils::current_time; events::Event,
inputs::bytes::BytesInput,
observers::StdMapObserver,
utils::current_time,
};
static mut MAP: [u32; 4] = [0; 4]; static mut MAP: [u32; 4] = [0; 4];
@ -254,10 +259,9 @@ mod tests {
time: _, time: _,
executions: _, executions: _,
} => { } => {
let o: tuple_list!(StdMapObserver::<u32>) = let o: tuple_list_type!(StdMapObserver::<u32>) =
postcard::from_bytes(&observers_buf).unwrap(); postcard::from_bytes(&observers_buf).unwrap();
let test_observer = o.match_name_type::<StdMapObserver<u32>>("test").unwrap(); assert_eq!("test", o.0.name());
assert_eq!("test", test_observer.name());
} }
_ => panic!("mistmatch"), _ => panic!("mistmatch"),
}; };

View File

@ -53,14 +53,19 @@ where
OT: ObserversTuple, OT: ObserversTuple,
{ {
#[inline] #[inline]
fn pre_exec<EM, S>(&mut self, state: &mut S, event_mgr: &mut EM, input: &I) -> Result<(), Error> fn pre_exec<EM, S>(
&mut self,
_state: &mut S,
_event_mgr: &mut EM,
_input: &I,
) -> Result<(), Error>
where where
EM: EventManager<I, S>, EM: EventManager<I, S>,
{ {
#[cfg(unix)] #[cfg(unix)]
#[cfg(feature = "std")] #[cfg(feature = "std")]
unsafe { unsafe {
set_oncrash_ptrs(state, event_mgr, self.observers(), input); set_oncrash_ptrs(_state, _event_mgr, self.observers(), _input);
} }
Ok(()) Ok(())
} }

View File

@ -32,11 +32,8 @@ pub trait Input: Clone + serde::Serialize + serde::de::DeserializeOwned + Debug
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
/// Write this input to the file /// Write this input to the file
fn to_file<P>(&self, _path: P) -> Result<(), Error> fn to_file<P>(&self, _path: P) -> Result<(), Error> {
where Err(Error::NotImplemented("Not supported in no_std".into()))
P: AsRef<Path>,
{
Err(Error::NotImplemented("Not suppored in no_std".into()))
} }
/// Load the contents of this input from a file /// Load the contents of this input from a file
@ -53,11 +50,8 @@ pub trait Input: Clone + serde::Serialize + serde::de::DeserializeOwned + Debug
/// Write this input to the file /// Write this input to the file
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
fn from_file<P>(_path: P) -> Result<Self, Error> fn from_file<P>(_path: P) -> Result<Self, Error> {
where Err(Error::NotImplemented("Not supprted in no_std".into()))
P: AsRef<Path>,
{
Err(Error::NotImplemented("Not suppored in no_std".into()))
} }
} }

View File

@ -8,6 +8,7 @@ Welcome to libAFL
extern crate alloc; extern crate alloc;
#[macro_use] #[macro_use]
extern crate static_assertions; extern crate static_assertions;
#[cfg(feature = "std")]
#[macro_use] #[macro_use]
extern crate ctor; extern crate ctor;

View File

@ -1,7 +1,10 @@
pub mod map; pub mod map;
pub use map::*; pub use map::*;
use alloc::string::{String, ToString}; use alloc::{
string::{String, ToString},
vec::Vec,
};
use core::time::Duration; use core::time::Duration;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};