aboutsummaryrefslogtreecommitdiff
path: root/custom_mutators/libafl_base
diff options
context:
space:
mode:
authorvan Hauser <vh@thc.org>2023-01-05 13:51:20 +0100
committerGitHub <noreply@github.com>2023-01-05 13:51:20 +0100
commit3b6fcd911a860a8c823c912c4b08b423734e4cfe (patch)
treecc2599499e847c4ac661988d1c5fe7b35a5ef82e /custom_mutators/libafl_base
parent60dc37a8cf09f8e9048e4b6a2204d6c90b27655a (diff)
parenta3b56e7280cb5b5cea21c66c40d4390db6f13b8f (diff)
downloadafl++-3b6fcd911a860a8c823c912c4b08b423734e4cfe.tar.gz
Merge pull request #1610 from AFLplusplus/dev4.05c
push to stable
Diffstat (limited to 'custom_mutators/libafl_base')
-rw-r--r--custom_mutators/libafl_base/Cargo.toml2
-rw-r--r--custom_mutators/libafl_base/src/lib.rs36
2 files changed, 26 insertions, 12 deletions
diff --git a/custom_mutators/libafl_base/Cargo.toml b/custom_mutators/libafl_base/Cargo.toml
index 6e40fc39..ac6b0c8f 100644
--- a/custom_mutators/libafl_base/Cargo.toml
+++ b/custom_mutators/libafl_base/Cargo.toml
@@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-libafl = { git = "https://github.com/AFLplusplus/LibAFL.git", rev = "62614ce1016c86e3f00f35b56399292ceabd486b" }
+libafl = { git = "https://github.com/AFLplusplus/LibAFL.git", rev = "266677bb88abe75165430f34e7de897c35560504" }
custom_mutator = { path = "../rust/custom_mutator", features = ["afl_internals"] }
serde = { version = "1.0", default-features = false, features = ["alloc"] } # serialization lib
diff --git a/custom_mutators/libafl_base/src/lib.rs b/custom_mutators/libafl_base/src/lib.rs
index 6f2db8ca..bae11e1f 100644
--- a/custom_mutators/libafl_base/src/lib.rs
+++ b/custom_mutators/libafl_base/src/lib.rs
@@ -1,5 +1,4 @@
#![cfg(unix)]
-#![allow(unused_variables)]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::{
@@ -18,10 +17,12 @@ use libafl::{
scheduled::{havoc_mutations, tokens_mutations, StdScheduledMutator, Tokens},
Mutator,
},
- state::{HasCorpus, HasMaxSize, HasMetadata, HasRand, State},
+ prelude::UsesInput,
+ state::{HasCorpus, HasMaxSize, HasMetadata, HasRand, State, UsesState},
Error,
};
+#[allow(clippy::identity_op)]
const MAX_FILE: usize = 1 * 1024 * 1024;
static mut AFL: Option<&'static afl_state> = None;
@@ -64,24 +65,32 @@ impl<'de> Deserialize<'de> for AFLCorpus {
}
}
-impl Corpus<BytesInput> for AFLCorpus {
+impl UsesState for AFLCorpus {
+ type State = AFLState;
+}
+
+impl Corpus for AFLCorpus {
#[inline]
fn count(&self) -> usize {
afl().queued_items as usize
}
#[inline]
- fn add(&mut self, testcase: Testcase<BytesInput>) -> Result<usize, Error> {
+ fn add(&mut self, _testcase: Testcase<BytesInput>) -> Result<usize, Error> {
unimplemented!();
}
#[inline]
- fn replace(&mut self, idx: usize, testcase: Testcase<BytesInput>) -> Result<(), Error> {
+ fn replace(
+ &mut self,
+ _idx: usize,
+ _testcase: Testcase<BytesInput>,
+ ) -> Result<Testcase<Self::Input>, Error> {
unimplemented!();
}
#[inline]
- fn remove(&mut self, idx: usize) -> Result<Option<Testcase<BytesInput>>, Error> {
+ fn remove(&mut self, _idx: usize) -> Result<Option<Testcase<BytesInput>>, Error> {
unimplemented!();
}
@@ -92,7 +101,7 @@ impl Corpus<BytesInput> for AFLCorpus {
entries.entry(idx).or_insert_with(|| {
let queue_buf = std::slice::from_raw_parts_mut(afl().queue_buf, self.count());
let entry = queue_buf[idx].as_mut().unwrap();
- let fname = CStr::from_ptr((entry.fname as *mut i8).as_ref().unwrap())
+ let fname = CStr::from_ptr((entry.fname.cast::<i8>()).as_ref().unwrap())
.to_str()
.unwrap()
.to_owned();
@@ -127,9 +136,10 @@ pub struct AFLState {
}
impl AFLState {
+ #[must_use]
pub fn new(seed: u32) -> Self {
Self {
- rand: StdRand::with_seed(seed as u64),
+ rand: StdRand::with_seed(u64::from(seed)),
corpus: AFLCorpus::default(),
metadata: SerdeAnyMap::new(),
max_size: MAX_FILE,
@@ -153,7 +163,11 @@ impl HasRand for AFLState {
}
}
-impl HasCorpus<BytesInput> for AFLState {
+impl UsesInput for AFLState {
+ type Input = BytesInput;
+}
+
+impl HasCorpus for AFLState {
type Corpus = AFLCorpus;
#[inline]
@@ -208,7 +222,7 @@ impl CustomMutator for LibAFLBaseCustomMutator {
tokens.push(data.to_vec());
}
if !tokens.is_empty() {
- state.add_metadata(Tokens::new(tokens));
+ state.add_metadata(Tokens::from(tokens));
}
Ok(Self {
state,
@@ -220,7 +234,7 @@ impl CustomMutator for LibAFLBaseCustomMutator {
fn fuzz<'b, 's: 'b>(
&'s mut self,
buffer: &'b mut [u8],
- add_buff: Option<&[u8]>,
+ _add_buff: Option<&[u8]>,
max_size: usize,
) -> Result<Option<&'b [u8]>, Self::Error> {
self.state.set_max_size(max_size);