Add unique_name() to Input. Use it to generate filename in OnDiskCorpus (#152)

* Add unique_name() to Input. Use unique_name to generate filename in OnDiskCorpus

* updated duplicate ahash

* nostd fixes

* fmt

* rename unique_name to generate_name

Co-authored-by: Dominik Maier <domenukk@gmail.com>
This commit is contained in:
s1341 2021-06-08 10:54:38 +03:00 committed by GitHub
parent cd9be5b33b
commit 4271790cb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 6 deletions

View File

@ -30,7 +30,6 @@ libc = "0.2"
libloading = "0.7.0" libloading = "0.7.0"
num-traits = "0.2.14" num-traits = "0.2.14"
rangemap = "0.1.10" rangemap = "0.1.10"
seahash = "4.1.0"
clap = "2.33" clap = "2.33"
serde = "1.0" serde = "1.0"

View File

@ -16,7 +16,7 @@ rustc_version = "0.3.3"
[dev-dependencies] [dev-dependencies]
criterion = "0.3" # Benchmarking criterion = "0.3" # Benchmarking
ahash = "0.6.1" # another hash ahash = "0.7" # another hash
fxhash = "0.2.1" # yet another hash fxhash = "0.2.1" # yet another hash
xxhash-rust = { version = "0.8.2", features = ["xxh3"] } # xxh3 hashing for rust xxhash-rust = { version = "0.8.2", features = ["xxh3"] } # xxh3 hashing for rust
serde_json = "1.0.60" serde_json = "1.0.60"
@ -68,6 +68,7 @@ core_affinity = { version = "0.5", git = "https://github.com/s1341/core_affinity
num_enum = "0.5.1" num_enum = "0.5.1"
hostname = "^0.3" # Is there really no gethostname in the stdlib? hostname = "^0.3" # Is there really no gethostname in the stdlib?
typed-builder = "0.9.0" typed-builder = "0.9.0"
ahash ="0.7"
[target.'cfg(target_os = "android")'.dependencies] [target.'cfg(target_os = "android")'.dependencies]
backtrace = { version = "0.3", optional = true, default-features = false, features = ["std", "libbacktrace"] } # for llmp_debug backtrace = { version = "0.3", optional = true, default-features = false, features = ["std", "libbacktrace"] } # for llmp_debug

View File

@ -50,7 +50,13 @@ where
fn add(&mut self, mut testcase: Testcase<I>) -> Result<usize, Error> { fn add(&mut self, mut testcase: Testcase<I>) -> Result<usize, Error> {
if testcase.filename().is_none() { if testcase.filename().is_none() {
// TODO walk entry metadata to ask for pices of filename (e.g. :havoc in AFL) // TODO walk entry metadata to ask for pices of filename (e.g. :havoc in AFL)
let filename = self.dir_path.join(format!("id_{}", &self.entries.len())); let filename = self.dir_path.join(
testcase
.input()
.as_ref()
.unwrap()
.generate_name(self.entries.len()),
);
let filename_str = filename.to_str().expect("Invalid Path"); let filename_str = filename.to_str().expect("Invalid Path");
testcase.set_filename(filename_str.into()); testcase.set_filename(filename_str.into());
}; };

View File

@ -1,7 +1,10 @@
//! The `BytesInput` is the "normal" input, a map of bytes, that can be sent directly to the client //! The `BytesInput` is the "normal" input, a map of bytes, that can be sent directly to the client
//! (As opposed to other, more abstract, imputs, like an Grammar-Based AST Input) //! (As opposed to other, more abstract, imputs, like an Grammar-Based AST Input)
use alloc::{borrow::ToOwned, rc::Rc, vec::Vec}; use ahash::AHasher;
use core::hash::Hasher;
use alloc::{borrow::ToOwned, rc::Rc, string::String, vec::Vec};
use core::{cell::RefCell, convert::From}; use core::{cell::RefCell, convert::From};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[cfg(feature = "std")] #[cfg(feature = "std")]
@ -48,6 +51,13 @@ impl Input for BytesInput {
file.read_to_end(&mut bytes)?; file.read_to_end(&mut bytes)?;
Ok(BytesInput::new(bytes)) Ok(BytesInput::new(bytes))
} }
/// Generate a name for this input
fn generate_name(&self, _idx: usize) -> String {
let mut hasher = AHasher::new_with_keys(0, 0);
hasher.write(self.bytes());
format!("{:016x}", hasher.finish())
}
} }
/// Rc Ref-cell from Input /// Rc Ref-cell from Input

View File

@ -3,7 +3,10 @@
pub mod bytes; pub mod bytes;
pub use bytes::BytesInput; pub use bytes::BytesInput;
use alloc::vec::Vec; use alloc::{
string::{String, ToString},
vec::Vec,
};
use core::{clone::Clone, fmt::Debug}; use core::{clone::Clone, fmt::Debug};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::{ use std::{
@ -53,12 +56,19 @@ pub trait Input: Clone + serde::Serialize + serde::de::DeserializeOwned + Debug
fn from_file<P>(_path: P) -> Result<Self, Error> { fn from_file<P>(_path: P) -> Result<Self, Error> {
Err(Error::NotImplemented("Not supprted in no_std".into())) Err(Error::NotImplemented("Not supprted in no_std".into()))
} }
/// Generate a name for this input
fn generate_name(&self, idx: usize) -> String;
} }
/// An input for tests, mainly. There is no real use much else. /// An input for tests, mainly. There is no real use much else.
#[derive(Copy, Clone, Serialize, Deserialize, Debug)] #[derive(Copy, Clone, Serialize, Deserialize, Debug)]
pub struct NopInput {} pub struct NopInput {}
impl Input for NopInput {} impl Input for NopInput {
fn generate_name(&self, _idx: usize) -> String {
"nop-input".to_string()
}
}
impl HasTargetBytes for NopInput { impl HasTargetBytes for NopInput {
fn target_bytes(&self) -> OwnedSlice<u8> { fn target_bytes(&self) -> OwnedSlice<u8> {
OwnedSlice::Owned(vec![0]) OwnedSlice::Owned(vec![0])