-
-
Notifications
You must be signed in to change notification settings - Fork 331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove MutVecInput and MappedInput in Favour of Impls on References #2783
Changes from 2 commits
31dfa59
2ec5392
c2396ef
7d4b21e
159981f
225e94d
c6a1081
647c4e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
# Pre 0.9 -> 0.9 | ||
- [Migrating from LibAFL <0.9 to 0.9](https://aflplus.plus/libafl-book/design/migration-0.9.html) | ||
|
||
# 0.14.0 -> 0.14.1 | ||
- Removed `with_observers` from `Executor` trait. | ||
- `MmapShMemProvider::new_shmem_persistent` has been removed in favour of `MmapShMem::persist`. You probably want to do something like this: `let shmem = MmapShMemProvider::new()?.new_shmem(size)?.persist()?;` | ||
|
||
# 0.14.1 -> 0.15.0 | ||
- `MmapShMem::new` and `MmapShMemProvider::new_shmem_with_id` now take `AsRef<Path>` instead of a byte array for the filename/id. | ||
- The closure passed to a `DumpToDiskStage` now provides the `Testcase` instead of just the `Input`. | ||
- `StatsStage` is deleted, and it is superceded by `AflStatsStage` | ||
- | ||
- Changed mapping mutators to take borrows directly instead of `MappedInput`s. See `baby_fuzzer_custom_input` for example usage | ||
- Related: `MutVecInput` is deprecated in favor of directly using `&mut Vec<u8>` | ||
- Related: `MappedInputFunctionMappingMutator` and `ToMappedInputFunctionMappingMutatorMapper` have been removed as now duplicates of `FunctionMappingMutator` `ToFunctionMappingMutatorMapper` | ||
|
||
# 0.14.0 -> 0.14.1 | ||
- Removed `with_observers` from `Executor` trait. | ||
- `MmapShMemProvider::new_shmem_persistent` has been removed in favour of `MmapShMem::persist`. You probably want to do something like this: `let shmem = MmapShMemProvider::new()?.new_shmem(size)?.persist()?;` | ||
|
||
# Pre 0.9 -> 0.9 | ||
- [Migrating from LibAFL <0.9 to 0.9](https://aflplus.plus/libafl-book/design/migration-0.9.html) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ use core::{ | |
clone::Clone, | ||
fmt::Debug, | ||
marker::PhantomData, | ||
ops::{Deref, DerefMut, RangeBounds}, | ||
ops::{DerefMut, RangeBounds}, | ||
}; | ||
#[cfg(feature = "std")] | ||
use std::{fs::File, hash::Hash, io::Read, path::Path}; | ||
|
@@ -50,7 +50,6 @@ use libafl_bolts::{ | |
#[cfg(feature = "nautilus")] | ||
pub use nautilus::*; | ||
use serde::{Deserialize, Serialize}; | ||
use value::ValueMutRefInput; | ||
|
||
use crate::corpus::CorpusId; | ||
|
||
|
@@ -198,36 +197,44 @@ pub trait HasMutatorBytes: HasLen { | |
} | ||
} | ||
|
||
/// Mapping types to themselves, used to ensure lifetime consistency for mapped mutators. | ||
/// | ||
/// Specifically, this is for [`Input`] types that are owned wrappers around a reference. The lifetime of the associated type should be the same as the reference. | ||
pub trait MappedInput { | ||
/// The type for which this trait is implemented | ||
type Type<'a> | ||
impl HasMutatorBytes for Vec<u8> { | ||
fn bytes(&self) -> &[u8] { | ||
self.as_ref() | ||
} | ||
|
||
fn bytes_mut(&mut self) -> &mut [u8] { | ||
self.as_mut() | ||
} | ||
|
||
fn resize(&mut self, new_len: usize, value: u8) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this make using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If, in the same file, one has |
||
<Vec<u8>>::resize(self, new_len, value); | ||
} | ||
|
||
fn extend<'a, I: IntoIterator<Item = &'a u8>>(&mut self, iter: I) { | ||
<Vec<u8> as Extend<I::Item>>::extend(self, iter); | ||
} | ||
|
||
fn splice<R, I>(&mut self, range: R, replace_with: I) -> Splice<'_, I::IntoIter> | ||
where | ||
Self: 'a; | ||
} | ||
R: RangeBounds<usize>, | ||
I: IntoIterator<Item = u8>, | ||
{ | ||
<Vec<u8>>::splice(self, range, replace_with) | ||
} | ||
|
||
impl<T> MappedInput for Option<T> | ||
where | ||
T: MappedInput, | ||
{ | ||
type Type<'a> | ||
= Option<T::Type<'a>> | ||
fn drain<R>(&mut self, range: R) -> Drain<'_, u8> | ||
where | ||
T: 'a; | ||
R: RangeBounds<usize>, | ||
{ | ||
<Vec<u8>>::drain(self, range) | ||
} | ||
} | ||
|
||
/// A wrapper type that allows us to use mutators for Mutators for `&mut `[`Vec`]. | ||
pub type MutVecInput<'a> = ValueMutRefInput<'a, Vec<u8>>; | ||
|
||
impl HasLen for MutVecInput<'_> { | ||
fn len(&self) -> usize { | ||
self.deref().len() | ||
} | ||
} | ||
#[deprecated(since = "0.15.0", note = "Use &mut Vec<u8> directly")] | ||
pub type MutVecInput<'a> = &'a mut Vec<u8>; | ||
|
||
impl HasMutatorBytes for MutVecInput<'_> { | ||
impl HasMutatorBytes for &mut Vec<u8> { | ||
fn bytes(&self) -> &[u8] { | ||
self | ||
} | ||
|
@@ -241,7 +248,7 @@ impl HasMutatorBytes for MutVecInput<'_> { | |
} | ||
|
||
fn extend<'b, I: IntoIterator<Item = &'b u8>>(&mut self, iter: I) { | ||
self.deref_mut().extend(iter); | ||
<Vec<u8> as Extend<I::Item>>::extend(self, iter); | ||
} | ||
|
||
fn splice<R, I>(&mut self, range: R, replace_with: I) -> Splice<'_, I::IntoIter> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!