Skip to content

Commit 56b37bb

Browse files
authored
Improve the libafl_libfuzzer corpus (#1539)
* improved libfuzzer corpus * use .into() for converting ids to usize * oops * fix warning about unused arg * fix some lingering CI errors * actually save the last lmao
1 parent fd98eab commit 56b37bb

File tree

10 files changed

+415
-81
lines changed

10 files changed

+415
-81
lines changed

libafl/src/corpus/inmemory.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ where
183183
/// Get the next id given a `CorpusId` (creation order)
184184
#[cfg(not(feature = "corpus_btreemap"))]
185185
#[must_use]
186-
fn next(&self, idx: CorpusId) -> Option<CorpusId> {
186+
pub fn next(&self, idx: CorpusId) -> Option<CorpusId> {
187187
if let Some(item) = self.map.get(&idx) {
188188
item.next
189189
} else {
@@ -194,7 +194,7 @@ where
194194
/// Get the next id given a `CorpusId` (creation order)
195195
#[cfg(feature = "corpus_btreemap")]
196196
#[must_use]
197-
fn next(&self, idx: CorpusId) -> Option<CorpusId> {
197+
pub fn next(&self, idx: CorpusId) -> Option<CorpusId> {
198198
// TODO see if using self.keys is faster
199199
let mut range = self
200200
.map
@@ -214,7 +214,7 @@ where
214214
/// Get the previous id given a `CorpusId` (creation order)
215215
#[cfg(not(feature = "corpus_btreemap"))]
216216
#[must_use]
217-
fn prev(&self, idx: CorpusId) -> Option<CorpusId> {
217+
pub fn prev(&self, idx: CorpusId) -> Option<CorpusId> {
218218
if let Some(item) = self.map.get(&idx) {
219219
item.prev
220220
} else {
@@ -225,7 +225,7 @@ where
225225
/// Get the previous id given a `CorpusId` (creation order)
226226
#[cfg(feature = "corpus_btreemap")]
227227
#[must_use]
228-
fn prev(&self, idx: CorpusId) -> Option<CorpusId> {
228+
pub fn prev(&self, idx: CorpusId) -> Option<CorpusId> {
229229
// TODO see if using self.keys is faster
230230
let mut range = self
231231
.map
@@ -245,28 +245,28 @@ where
245245
/// Get the first created id
246246
#[cfg(not(feature = "corpus_btreemap"))]
247247
#[must_use]
248-
fn first(&self) -> Option<CorpusId> {
248+
pub fn first(&self) -> Option<CorpusId> {
249249
self.first_idx
250250
}
251251

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

259259
/// Get the last created id
260260
#[cfg(not(feature = "corpus_btreemap"))]
261261
#[must_use]
262-
fn last(&self) -> Option<CorpusId> {
262+
pub fn last(&self) -> Option<CorpusId> {
263263
self.last_idx
264264
}
265265

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

libafl/src/monitors/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use core::{fmt, fmt::Write, time::Duration};
2121
#[cfg(feature = "std")]
2222
pub use disk::{OnDiskJSONMonitor, OnDiskTOMLMonitor};
2323
use hashbrown::HashMap;
24-
use libafl_bolts::{current_time, format_duration_hms, ClientId};
24+
use libafl_bolts::{current_time, format_duration_hms, ClientId, Error};
2525
use serde::{Deserialize, Serialize};
2626

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

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

libafl_bolts/src/lib.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ use alloc::vec::Vec;
140140
use core::hash::BuildHasher;
141141
#[cfg(any(feature = "xxh3", feature = "alloc"))]
142142
use core::hash::Hasher;
143-
use core::{iter::Iterator, time};
144143
#[cfg(feature = "std")]
145144
use std::time::{SystemTime, UNIX_EPOCH};
146145

@@ -175,18 +174,23 @@ pub mod launcher {}
175174
#[allow(unused_imports)]
176175
#[macro_use]
177176
extern crate libafl_derive;
178-
#[cfg(feature = "alloc")]
179-
use alloc::string::{FromUtf8Error, String};
180177
use core::{
181178
array::TryFromSliceError,
182179
fmt::{self, Display},
180+
iter::Iterator,
183181
num::{ParseIntError, TryFromIntError},
182+
time,
184183
};
185184
#[cfg(feature = "std")]
186185
use std::{env::VarError, io};
187186

188187
#[cfg(feature = "libafl_derive")]
189188
pub use libafl_derive::SerdeAny;
189+
#[cfg(feature = "alloc")]
190+
use {
191+
alloc::string::{FromUtf8Error, String},
192+
core::cell::{BorrowError, BorrowMutError},
193+
};
190194

191195
/// We need fixed names for many parts of this lib.
192196
pub trait Named {
@@ -444,6 +448,24 @@ impl Display for Error {
444448
}
445449
}
446450

451+
#[cfg(feature = "alloc")]
452+
impl From<BorrowError> for Error {
453+
fn from(err: BorrowError) -> Self {
454+
Self::illegal_state(format!(
455+
"Couldn't borrow from a RefCell as immutable: {err:?}"
456+
))
457+
}
458+
}
459+
460+
#[cfg(feature = "alloc")]
461+
impl From<BorrowMutError> for Error {
462+
fn from(err: BorrowMutError) -> Self {
463+
Self::illegal_state(format!(
464+
"Couldn't borrow from a RefCell as mutable: {err:?}"
465+
))
466+
}
467+
}
468+
447469
/// Stringify the postcard serializer error
448470
#[cfg(feature = "alloc")]
449471
impl From<postcard::Error> for Error {

libafl_libfuzzer/libafl_libfuzzer_runtime/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ log = "0.4.17"
4040
mimalloc = { version = "0.1.34", default-features = false, optional = true }
4141
num-traits = "0.2.15"
4242
rand = "0.8.5"
43-
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] } # serialization lib
43+
serde = { version = "1.0", features = ["derive"] } # serialization lib
4444

4545
# clippy-suggested optimised byte counter
4646
bytecount = "0.6.3"

0 commit comments

Comments
 (0)