Merge branch 'main' of github.com:AFLplusplus/libAFLrs into main

This commit is contained in:
Andrea Fioraldi 2020-12-17 14:27:18 +01:00
commit a625904399
4 changed files with 66 additions and 13 deletions

View File

@ -1,12 +1,12 @@
pub mod testcase; pub mod testcase;
pub use testcase::{Testcase}; pub use testcase::Testcase;
use alloc::borrow::ToOwned; use alloc::borrow::ToOwned;
use alloc::vec::Vec; use alloc::vec::Vec;
use core::cell::RefCell; use core::cell::RefCell;
use core::marker::PhantomData; use core::marker::PhantomData;
use core::ptr; use core::ptr;
use serde::{Serialize, Deserialize}; use serde::{Deserialize, Serialize};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::path::PathBuf; use std::path::PathBuf;

View File

@ -2,7 +2,7 @@
use core::fmt::Debug; use core::fmt::Debug;
use core::marker::PhantomData; use core::marker::PhantomData;
use serde::{Serialize, Deserialize}; use serde::{Deserialize, Serialize};
use crate::corpus::{Corpus, Testcase}; use crate::corpus::{Corpus, Testcase};
use crate::events::EventManager; use crate::events::EventManager;
@ -11,8 +11,8 @@ use crate::feedbacks::FeedbacksTuple;
use crate::generators::Generator; use crate::generators::Generator;
use crate::inputs::Input; use crate::inputs::Input;
use crate::observers::ObserversTuple; use crate::observers::ObserversTuple;
use crate::stages::StagesTuple;
use crate::serde_anymap::{SerdeAny, SerdeAnyMap}; use crate::serde_anymap::{SerdeAny, SerdeAnyMap};
use crate::stages::StagesTuple;
use crate::tuples::{tuple_list, tuple_list_type}; use crate::tuples::{tuple_list, tuple_list_type};
use crate::utils::{current_milliseconds, Rand}; use crate::utils::{current_milliseconds, Rand};
use crate::AflError; use crate::AflError;
@ -420,7 +420,7 @@ mod tests {
use crate::inputs::bytes::BytesInput; use crate::inputs::bytes::BytesInput;
use crate::mutators::{mutation_bitflip, ComposedByMutations, StdScheduledMutator}; use crate::mutators::{mutation_bitflip, ComposedByMutations, StdScheduledMutator};
use crate::stages::mutational::StdMutationalStage; use crate::stages::mutational::StdMutationalStage;
use crate::tuples::{tuple_list_type, tuple_list}; use crate::tuples::{tuple_list, tuple_list_type};
use crate::utils::StdRand; use crate::utils::StdRand;
fn harness<I>(_executor: &dyn Executor<I>, _buf: &[u8]) -> ExitKind { fn harness<I>(_executor: &dyn Executor<I>, _buf: &[u8]) -> ExitKind {
@ -460,11 +460,13 @@ mod tests {
} }
let state_serialized = postcard::to_allocvec(&state).unwrap(); let state_serialized = postcard::to_allocvec(&state).unwrap();
let state_deserialized: State<BytesInput, StdRand, tuple_list_type!(), tuple_list_type!()> = postcard::from_bytes(state_serialized.as_slice()).unwrap(); let state_deserialized: State<BytesInput, StdRand, tuple_list_type!(), tuple_list_type!()> =
postcard::from_bytes(state_serialized.as_slice()).unwrap();
assert_eq!(state.executions, state_deserialized.executions); assert_eq!(state.executions, state_deserialized.executions);
let corpus_serialized = postcard::to_allocvec(&corpus).unwrap(); let corpus_serialized = postcard::to_allocvec(&corpus).unwrap();
let corpus_deserialized: InMemoryCorpus<BytesInput, StdRand> = postcard::from_bytes(corpus_serialized.as_slice()).unwrap(); let corpus_deserialized: InMemoryCorpus<BytesInput, StdRand> =
postcard::from_bytes(corpus_serialized.as_slice()).unwrap();
assert_eq!(corpus.count(), corpus_deserialized.count()); assert_eq!(corpus.count(), corpus_deserialized.count());
} }
} }

View File

@ -1135,7 +1135,6 @@ impl LlmpClient {
} }
} }
/*
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
@ -1143,6 +1142,7 @@ mod tests {
use super::{ use super::{
LlmpConnection::{self, IsBroker, IsClient}, LlmpConnection::{self, IsBroker, IsClient},
LlmpMsgHookResult::ForwardToClients,
Tag, Tag,
}; };
@ -1167,15 +1167,19 @@ mod tests {
// Give the (background) tcp thread a few millis to post the message // Give the (background) tcp thread a few millis to post the message
sleep(Duration::from_millis(100)); sleep(Duration::from_millis(100));
broker.once().unwrap(); broker
.once(&mut |_sender_id, _tag, _msg| Ok(ForwardToClients))
.unwrap();
let tag: Tag = 0x1337; let tag: Tag = 0x1337;
let arr: [u8; 1] = [1u8]; let arr: [u8; 1] = [1u8];
// Send stuff // Send stuff
client.send_buf(tag, &arr).unwrap(); client.send_buf(tag, &arr).unwrap();
// Forward stuff to clients // Forward stuff to clients
broker.once().unwrap(); broker
let (tag2, arr2) = client.recv_buf_blocking().unwrap(); .once(&mut |_sender_id, _tag, _msg| Ok(ForwardToClients))
.unwrap();
let (_sender_id, tag2, arr2) = client.recv_buf_blocking().unwrap();
assert_eq!(tag, tag2); assert_eq!(tag, tag2);
assert_eq!(arr[0], arr2[0]); assert_eq!(arr[0], arr2[0]);
@ -1183,4 +1187,3 @@ mod tests {
assert_eq!(broker.llmp_clients.len(), 2); assert_eq!(broker.llmp_clients.len(), 2);
} }
} }
*/

View File

@ -1,6 +1,8 @@
pub mod inmemory; pub mod inmemory;
use crate::inputs::Input; use core::marker::PhantomData;
use crate::inputs::{HasTargetBytes, Input};
use crate::observers::ObserversTuple; use crate::observers::ObserversTuple;
use crate::tuples::{MatchNameAndType, MatchType, Named, TupleList}; use crate::tuples::{MatchNameAndType, MatchType, Named, TupleList};
use crate::AflError; use crate::AflError;
@ -36,6 +38,31 @@ where
} }
} }
/// A simple executor that does nothing.
/// If intput len is 0, run_target will return Err
struct NopExecutor<I> {
phantom: PhantomData<I>,
}
impl<I> Executor<I> for NopExecutor<I>
where
I: Input + HasTargetBytes,
{
fn run_target(&mut self, input: &I) -> Result<ExitKind, AflError> {
if input.target_bytes().as_slice().len() == 0 {
Err(AflError::Empty("Input Empty".into()))
} else {
Ok(ExitKind::Ok)
}
}
}
impl<I> Named for NopExecutor<I> {
fn name(&self) -> &str {
&"NopExecutor"
}
}
/// An executor takes the given inputs, and runs the harness/target. /// An executor takes the given inputs, and runs the harness/target.
pub trait Executor<I>: Named pub trait Executor<I>: Named
where where
@ -77,3 +104,24 @@ where
self.1.for_each_mut(f) self.1.for_each_mut(f)
} }
} }
#[cfg(test)]
mod test {
use core::marker::PhantomData;
use crate::executors::Executor;
use crate::inputs::BytesInput;
use super::NopExecutor;
#[test]
fn nop_executor() {
let empty_input = BytesInput::new(vec![]);
let nonempty_input = BytesInput::new(vec![1u8]);
let mut executor = NopExecutor {
phantom: PhantomData,
};
assert!(executor.run_target(&empty_input).is_err());
assert!(executor.run_target(&nonempty_input).is_ok());
}
}