Skip to content

Commit 4c17da0

Browse files
Clipped Fixxy (#1622)
* clippy fix * fix * fix * it works * imports
1 parent 67aa5b1 commit 4c17da0

File tree

12 files changed

+245
-97
lines changed

12 files changed

+245
-97
lines changed

libafl/src/events/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub type ShutdownFuncPtr =
7777
///
7878
/// This will acceess `data` and write to the global `data.staterestorer_ptr` if it's not null.
7979
#[cfg(all(unix, feature = "std"))]
80+
#[allow(clippy::needless_pass_by_value)]
8081
pub unsafe fn shutdown_handler<SP>(
8182
signal: Signal,
8283
_info: &mut siginfo_t,

libafl/src/executors/inprocess.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! It should usually be paired with extra error-handling, such as a restarting event manager, to be effective.
33
//!
44
//! Needs the `fork` feature flag.
5+
#![allow(clippy::needless_pass_by_value)]
56

67
use alloc::boxed::Box;
78
#[cfg(all(unix, feature = "std"))]

libafl/src/mutators/token_mutations.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ impl Tokens {
223223
pub fn tokens(&self) -> &[Vec<u8>] {
224224
&self.tokens_vec
225225
}
226+
227+
/// Returns an iterator over the tokens.
228+
pub fn iter(&self) -> Iter<'_, Vec<u8>> {
229+
<&Self as IntoIterator>::into_iter(self)
230+
}
226231
}
227232

228233
impl AddAssign for Tokens {

libafl/src/observers/concolic/serialization_format.rs

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -381,66 +381,6 @@ impl<W: Write + Seek> MessageFileWriter<W> {
381381
}
382382
}
383383

384-
#[cfg(test)]
385-
mod serialization_tests {
386-
use alloc::vec::Vec;
387-
use std::io::Cursor;
388-
389-
use super::{MessageFileReader, MessageFileWriter, SymExpr};
390-
391-
/// This test intends to ensure that the serialization format can efficiently encode the required information.
392-
/// This is mainly useful to fail if any changes should be made in the future that (inadvertently) reduce
393-
/// serialization efficiency.
394-
#[test]
395-
fn efficient_serialization() {
396-
let mut buf = Vec::new();
397-
{
398-
let mut cursor = Cursor::new(&mut buf);
399-
let mut writer = MessageFileWriter::from_writer(&mut cursor).unwrap();
400-
let a = writer.write_message(SymExpr::True).unwrap();
401-
let b = writer.write_message(SymExpr::True).unwrap();
402-
writer.write_message(SymExpr::And { a, b }).unwrap();
403-
writer.update_trace_header().unwrap();
404-
}
405-
let expected_size = 8 + // the header takes 8 bytes to encode the length of the trace
406-
1 + // tag to create SymExpr::True (a)
407-
1 + // tag to create SymExpr::True (b)
408-
1 + // tag to create SymExpr::And
409-
1 + // reference to a
410-
1; // reference to b
411-
assert_eq!(buf.len(), expected_size);
412-
}
413-
414-
/// This test intends to verify that a trace written by [`MessageFileWriter`] can indeed be read back by
415-
/// [`MessageFileReader`].
416-
#[test]
417-
fn serialization_roundtrip() {
418-
let mut buf = Vec::new();
419-
{
420-
let mut cursor = Cursor::new(&mut buf);
421-
let mut writer = MessageFileWriter::from_writer(&mut cursor).unwrap();
422-
let a = writer.write_message(SymExpr::True).unwrap();
423-
let b = writer.write_message(SymExpr::True).unwrap();
424-
writer.write_message(SymExpr::And { a, b }).unwrap();
425-
writer.update_trace_header().unwrap();
426-
}
427-
let mut reader = MessageFileReader::from_length_prefixed_buffer(&buf).unwrap();
428-
let (first_bool_id, first_bool) = reader.next_message().unwrap().unwrap();
429-
assert_eq!(first_bool, SymExpr::True);
430-
let (second_bool_id, second_bool) = reader.next_message().unwrap().unwrap();
431-
assert_eq!(second_bool, SymExpr::True);
432-
let (_, and) = reader.next_message().unwrap().unwrap();
433-
assert_eq!(
434-
and,
435-
SymExpr::And {
436-
a: first_bool_id,
437-
b: second_bool_id
438-
}
439-
);
440-
assert!(reader.next_message().is_none());
441-
}
442-
}
443-
444384
use libafl_bolts::shmem::{ShMem, ShMemCursor, ShMemProvider, StdShMemProvider};
445385

446386
/// The default environment variable name to use for the shared memory used by the concolic tracing
@@ -511,3 +451,63 @@ impl MessageFileWriter<ShMemCursor<<StdShMemProvider as ShMemProvider>::ShMem>>
511451
/// A writer that will write messages to a shared memory buffer.
512452
pub type StdShMemMessageFileWriter =
513453
MessageFileWriter<ShMemCursor<<StdShMemProvider as ShMemProvider>::ShMem>>;
454+
455+
#[cfg(test)]
456+
mod serialization_tests {
457+
use alloc::vec::Vec;
458+
use std::io::Cursor;
459+
460+
use super::{MessageFileReader, MessageFileWriter, SymExpr};
461+
462+
/// This test intends to ensure that the serialization format can efficiently encode the required information.
463+
/// This is mainly useful to fail if any changes should be made in the future that (inadvertently) reduce
464+
/// serialization efficiency.
465+
#[test]
466+
fn efficient_serialization() {
467+
let mut buf = Vec::new();
468+
{
469+
let mut cursor = Cursor::new(&mut buf);
470+
let mut writer = MessageFileWriter::from_writer(&mut cursor).unwrap();
471+
let a = writer.write_message(SymExpr::True).unwrap();
472+
let b = writer.write_message(SymExpr::True).unwrap();
473+
writer.write_message(SymExpr::And { a, b }).unwrap();
474+
writer.update_trace_header().unwrap();
475+
}
476+
let expected_size = 8 + // the header takes 8 bytes to encode the length of the trace
477+
1 + // tag to create SymExpr::True (a)
478+
1 + // tag to create SymExpr::True (b)
479+
1 + // tag to create SymExpr::And
480+
1 + // reference to a
481+
1; // reference to b
482+
assert_eq!(buf.len(), expected_size);
483+
}
484+
485+
/// This test intends to verify that a trace written by [`MessageFileWriter`] can indeed be read back by
486+
/// [`MessageFileReader`].
487+
#[test]
488+
fn serialization_roundtrip() {
489+
let mut buf = Vec::new();
490+
{
491+
let mut cursor = Cursor::new(&mut buf);
492+
let mut writer = MessageFileWriter::from_writer(&mut cursor).unwrap();
493+
let a = writer.write_message(SymExpr::True).unwrap();
494+
let b = writer.write_message(SymExpr::True).unwrap();
495+
writer.write_message(SymExpr::And { a, b }).unwrap();
496+
writer.update_trace_header().unwrap();
497+
}
498+
let mut reader = MessageFileReader::from_length_prefixed_buffer(&buf).unwrap();
499+
let (first_bool_id, first_bool) = reader.next_message().unwrap().unwrap();
500+
assert_eq!(first_bool, SymExpr::True);
501+
let (second_bool_id, second_bool) = reader.next_message().unwrap().unwrap();
502+
assert_eq!(second_bool, SymExpr::True);
503+
let (_, and) = reader.next_message().unwrap().unwrap();
504+
assert_eq!(
505+
and,
506+
SymExpr::And {
507+
a: first_bool_id,
508+
b: second_bool_id
509+
}
510+
);
511+
assert!(reader.next_message().is_none());
512+
}
513+
}

libafl/src/observers/map.rs

Lines changed: 144 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,28 @@ where
324324
}
325325
}
326326

327+
impl<'a, T, const DIFFERENTIAL: bool> StdMapObserver<'a, T, DIFFERENTIAL>
328+
where
329+
T: Bounded
330+
+ PartialEq
331+
+ Default
332+
+ Copy
333+
+ 'static
334+
+ Serialize
335+
+ serde::de::DeserializeOwned
336+
+ Debug,
337+
{
338+
/// Returns an iterator over the map.
339+
pub fn iter(&self) -> Iter<'_, T> {
340+
<&Self as IntoIterator>::into_iter(self)
341+
}
342+
343+
/// Returns a mutable iterator over the map.
344+
pub fn iter_mut(&mut self) -> IterMut<'_, T> {
345+
<&mut Self as IntoIterator>::into_iter(self)
346+
}
347+
}
348+
327349
impl<'a, T, const DIFFERENTIAL: bool> MapObserver for StdMapObserver<'a, T, DIFFERENTIAL>
328350
where
329351
T: Bounded
@@ -781,6 +803,28 @@ where
781803
}
782804
}
783805

806+
impl<'a, T, const N: usize> ConstMapObserver<'a, T, N>
807+
where
808+
T: Bounded
809+
+ PartialEq
810+
+ Default
811+
+ Copy
812+
+ 'static
813+
+ Serialize
814+
+ serde::de::DeserializeOwned
815+
+ Debug,
816+
{
817+
/// Returns an iterator over the map.
818+
pub fn iter(&self) -> Iter<'_, T> {
819+
<&Self as IntoIterator>::into_iter(self)
820+
}
821+
822+
/// Returns a mutable iterator over the map.
823+
pub fn iter_mut(&mut self) -> IterMut<'_, T> {
824+
<&mut Self as IntoIterator>::into_iter(self)
825+
}
826+
}
827+
784828
impl<'a, T, const N: usize> MapObserver for ConstMapObserver<'a, T, N>
785829
where
786830
T: Bounded
@@ -1054,6 +1098,28 @@ where
10541098
}
10551099
}
10561100

1101+
impl<'a, T> VariableMapObserver<'a, T>
1102+
where
1103+
T: Bounded
1104+
+ PartialEq
1105+
+ Default
1106+
+ Copy
1107+
+ 'static
1108+
+ Serialize
1109+
+ serde::de::DeserializeOwned
1110+
+ Debug,
1111+
{
1112+
/// Returns an iterator over the map.
1113+
pub fn iter(&self) -> Iter<'_, T> {
1114+
<&Self as IntoIterator>::into_iter(self)
1115+
}
1116+
1117+
/// Returns a mutable iterator over the map.
1118+
pub fn iter_mut(&mut self) -> IterMut<'_, T> {
1119+
<&mut Self as IntoIterator>::into_iter(self)
1120+
}
1121+
}
1122+
10571123
impl<'a, T> MapObserver for VariableMapObserver<'a, T>
10581124
where
10591125
T: Bounded
@@ -1412,7 +1478,7 @@ where
14121478

14131479
impl<'it, M> IntoIterator for &'it HitcountsMapObserver<M>
14141480
where
1415-
M: Named + Serialize + serde::de::DeserializeOwned,
1481+
M: Serialize + serde::de::DeserializeOwned,
14161482
&'it M: IntoIterator<Item = &'it u8>,
14171483
{
14181484
type Item = &'it u8;
@@ -1425,7 +1491,7 @@ where
14251491

14261492
impl<'it, M> IntoIterator for &'it mut HitcountsMapObserver<M>
14271493
where
1428-
M: Named + Serialize + serde::de::DeserializeOwned,
1494+
M: Serialize + serde::de::DeserializeOwned,
14291495
&'it mut M: IntoIterator<Item = &'it mut u8>,
14301496
{
14311497
type Item = &'it mut u8;
@@ -1436,6 +1502,28 @@ where
14361502
}
14371503
}
14381504

1505+
impl<M> HitcountsMapObserver<M>
1506+
where
1507+
M: Serialize + serde::de::DeserializeOwned,
1508+
for<'it> &'it M: IntoIterator<Item = &'it u8>,
1509+
{
1510+
/// Returns an iterator over the map.
1511+
pub fn iter(&self) -> <&M as IntoIterator>::IntoIter {
1512+
<&Self as IntoIterator>::into_iter(self)
1513+
}
1514+
}
1515+
1516+
impl<M> HitcountsMapObserver<M>
1517+
where
1518+
M: Serialize + serde::de::DeserializeOwned,
1519+
for<'it> &'it mut M: IntoIterator<Item = &'it mut u8>,
1520+
{
1521+
/// Returns a mutable iterator over the map.
1522+
pub fn iter_mut(&mut self) -> <&mut M as IntoIterator>::IntoIter {
1523+
<&mut Self as IntoIterator>::into_iter(self)
1524+
}
1525+
}
1526+
14391527
impl<M, OTA, OTB, S> DifferentialObserver<OTA, OTB, S> for HitcountsMapObserver<M>
14401528
where
14411529
M: DifferentialObserver<OTA, OTB, S>
@@ -1639,7 +1727,7 @@ where
16391727

16401728
impl<'it, M> IntoIterator for &'it HitcountsIterableMapObserver<M>
16411729
where
1642-
M: Named + Serialize + serde::de::DeserializeOwned,
1730+
M: Serialize + serde::de::DeserializeOwned,
16431731
&'it M: IntoIterator<Item = &'it u8>,
16441732
{
16451733
type Item = &'it u8;
@@ -1652,7 +1740,7 @@ where
16521740

16531741
impl<'it, M> IntoIterator for &'it mut HitcountsIterableMapObserver<M>
16541742
where
1655-
M: Named + Serialize + serde::de::DeserializeOwned,
1743+
M: Serialize + serde::de::DeserializeOwned,
16561744
&'it mut M: IntoIterator<Item = &'it mut u8>,
16571745
{
16581746
type Item = &'it mut u8;
@@ -1663,6 +1751,28 @@ where
16631751
}
16641752
}
16651753

1754+
impl<M> HitcountsIterableMapObserver<M>
1755+
where
1756+
M: Serialize + serde::de::DeserializeOwned,
1757+
for<'it> &'it M: IntoIterator<Item = &'it u8>,
1758+
{
1759+
/// Returns an iterator over the map.
1760+
pub fn iter(&self) -> <&M as IntoIterator>::IntoIter {
1761+
<&Self as IntoIterator>::into_iter(self)
1762+
}
1763+
}
1764+
1765+
impl<M> HitcountsIterableMapObserver<M>
1766+
where
1767+
M: Serialize + serde::de::DeserializeOwned,
1768+
for<'it> &'it mut M: IntoIterator<Item = &'it mut u8>,
1769+
{
1770+
/// Returns a mutable iterator over the map.
1771+
pub fn iter_mut(&mut self) -> <&mut M as IntoIterator>::IntoIter {
1772+
<&mut Self as IntoIterator>::into_iter(self)
1773+
}
1774+
}
1775+
16661776
impl<M, OTA, OTB, S> DifferentialObserver<OTA, OTB, S> for HitcountsIterableMapObserver<M>
16671777
where
16681778
M: MapObserver<Entry = u8> + Observer<S> + DifferentialObserver<OTA, OTB, S>,
@@ -1967,6 +2077,21 @@ where
19672077
}
19682078
}
19692079

2080+
impl<'a, T, const DIFFERENTIAL: bool> MultiMapObserver<'a, T, DIFFERENTIAL>
2081+
where
2082+
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
2083+
{
2084+
/// Returns an iterator over the map.
2085+
pub fn iter(&self) -> <&Self as IntoIterator>::IntoIter {
2086+
<&Self as IntoIterator>::into_iter(self)
2087+
}
2088+
2089+
/// Returns a mutable iterator over the map.
2090+
pub fn iter_mut(&mut self) -> <&mut Self as IntoIterator>::IntoIter {
2091+
<&mut Self as IntoIterator>::into_iter(self)
2092+
}
2093+
}
2094+
19702095
impl<'a, T, OTA, OTB, S> DifferentialObserver<OTA, OTB, S> for MultiMapObserver<'a, T, true>
19712096
where
19722097
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
@@ -2071,6 +2196,21 @@ where
20712196
}
20722197
}
20732198

2199+
impl<T> OwnedMapObserver<T>
2200+
where
2201+
T: Default + Copy + 'static + Serialize + serde::de::DeserializeOwned + Debug,
2202+
{
2203+
/// Returns an iterator over the map.
2204+
pub fn iter(&self) -> Iter<'_, T> {
2205+
<&Self as IntoIterator>::into_iter(self)
2206+
}
2207+
2208+
/// Returns a mutable iterator over the map.
2209+
pub fn iter_mut(&mut self) -> IterMut<'_, T> {
2210+
<&mut Self as IntoIterator>::into_iter(self)
2211+
}
2212+
}
2213+
20742214
impl<T> MapObserver for OwnedMapObserver<T>
20752215
where
20762216
T: Bounded

libafl/src/observers/stacktrace.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::{
1919

2020
use backtrace::Backtrace;
2121
use libafl_bolts::{ownedref::OwnedRefMut, Named};
22+
#[allow(unused_imports)]
2223
#[cfg(feature = "casr")]
2324
use libcasr::{
2425
asan::AsanStacktrace,

0 commit comments

Comments
 (0)