Skip to content
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

Improve the libafl_libfuzzer corpus #1539

Merged
merged 6 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions libafl/src/corpus/inmemory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ where
/// Get the next id given a `CorpusId` (creation order)
#[cfg(not(feature = "corpus_btreemap"))]
#[must_use]
fn next(&self, idx: CorpusId) -> Option<CorpusId> {
pub fn next(&self, idx: CorpusId) -> Option<CorpusId> {
if let Some(item) = self.map.get(&idx) {
item.next
} else {
Expand All @@ -194,7 +194,7 @@ where
/// Get the next id given a `CorpusId` (creation order)
#[cfg(feature = "corpus_btreemap")]
#[must_use]
fn next(&self, idx: CorpusId) -> Option<CorpusId> {
pub fn next(&self, idx: CorpusId) -> Option<CorpusId> {
// TODO see if using self.keys is faster
let mut range = self
.map
Expand All @@ -214,7 +214,7 @@ where
/// Get the previous id given a `CorpusId` (creation order)
#[cfg(not(feature = "corpus_btreemap"))]
#[must_use]
fn prev(&self, idx: CorpusId) -> Option<CorpusId> {
pub fn prev(&self, idx: CorpusId) -> Option<CorpusId> {
if let Some(item) = self.map.get(&idx) {
item.prev
} else {
Expand All @@ -225,7 +225,7 @@ where
/// Get the previous id given a `CorpusId` (creation order)
#[cfg(feature = "corpus_btreemap")]
#[must_use]
fn prev(&self, idx: CorpusId) -> Option<CorpusId> {
pub fn prev(&self, idx: CorpusId) -> Option<CorpusId> {
// TODO see if using self.keys is faster
let mut range = self
.map
Expand All @@ -245,28 +245,28 @@ where
/// Get the first created id
#[cfg(not(feature = "corpus_btreemap"))]
#[must_use]
fn first(&self) -> Option<CorpusId> {
pub fn first(&self) -> Option<CorpusId> {
self.first_idx
}

/// Get the first created id
#[cfg(feature = "corpus_btreemap")]
#[must_use]
fn first(&self) -> Option<CorpusId> {
pub fn first(&self) -> Option<CorpusId> {
self.map.iter().next().map(|x| *x.0)
}

/// Get the last created id
#[cfg(not(feature = "corpus_btreemap"))]
#[must_use]
fn last(&self) -> Option<CorpusId> {
pub fn last(&self) -> Option<CorpusId> {
self.last_idx
}

/// Get the last created id
#[cfg(feature = "corpus_btreemap")]
#[must_use]
fn last(&self) -> Option<CorpusId> {
pub fn last(&self) -> Option<CorpusId> {
self.map.iter().next_back().map(|x| *x.0)
}

Expand Down
3 changes: 2 additions & 1 deletion libafl/src/monitors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use core::{fmt, fmt::Write, time::Duration};
#[cfg(feature = "std")]
pub use disk::{OnDiskJSONMonitor, OnDiskTOMLMonitor};
use hashbrown::HashMap;
use libafl_bolts::{current_time, format_duration_hms, ClientId};
use libafl_bolts::{current_time, format_duration_hms, ClientId, Error};
use serde::{Deserialize, Serialize};

#[cfg(feature = "afl_exec_sec")]
Expand Down Expand Up @@ -210,6 +210,7 @@ impl ClientStats {

/// Update the user-defined stat with name and value
pub fn update_user_stats(&mut self, name: String, value: UserStats) {
log::info!("{}", Error::unknown("dumping backtrace for monitoring"));
self.user_monitor.insert(name, value);
}

Expand Down
28 changes: 25 additions & 3 deletions libafl_bolts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ use alloc::vec::Vec;
use core::hash::BuildHasher;
#[cfg(any(feature = "xxh3", feature = "alloc"))]
use core::hash::Hasher;
use core::{iter::Iterator, time};
#[cfg(feature = "std")]
use std::time::{SystemTime, UNIX_EPOCH};

Expand Down Expand Up @@ -174,18 +173,23 @@ pub mod launcher {}
#[allow(unused_imports)]
#[macro_use]
extern crate libafl_derive;
#[cfg(feature = "alloc")]
use alloc::string::{FromUtf8Error, String};
use core::{
array::TryFromSliceError,
fmt::{self, Display},
iter::Iterator,
num::{ParseIntError, TryFromIntError},
time,
};
#[cfg(feature = "std")]
use std::{env::VarError, io};

#[cfg(feature = "libafl_derive")]
pub use libafl_derive::SerdeAny;
#[cfg(feature = "alloc")]
use {
alloc::string::{FromUtf8Error, String},
core::cell::{BorrowError, BorrowMutError},
};

/// We need fixed names for many parts of this lib.
pub trait Named {
Expand Down Expand Up @@ -443,6 +447,24 @@ impl Display for Error {
}
}

#[cfg(feature = "alloc")]
impl From<BorrowError> for Error {
fn from(err: BorrowError) -> Self {
Self::illegal_state(format!(
"Couldn't borrow from a RefCell as immutable: {err:?}"
))
}
}

#[cfg(feature = "alloc")]
impl From<BorrowMutError> for Error {
fn from(err: BorrowMutError) -> Self {
Self::illegal_state(format!(
"Couldn't borrow from a RefCell as mutable: {err:?}"
))
}
}

/// Stringify the postcard serializer error
#[cfg(feature = "alloc")]
impl From<postcard::Error> for Error {
Expand Down
2 changes: 1 addition & 1 deletion libafl_libfuzzer/libafl_libfuzzer_runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ log = "0.4.17"
mimalloc = { version = "0.1.34", default-features = false, optional = true }
num-traits = "0.2.15"
rand = "0.8.5"
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] } # serialization lib
serde = { version = "1.0", features = ["derive"] } # serialization lib

# clippy-suggested optimised byte counter
bytecount = "0.6.3"
Expand Down
Loading
Loading