Skip to content

Commit e36f5a6

Browse files
committed
fixup for artifact generation
1 parent f3529de commit e36f5a6

File tree

5 files changed

+60
-19
lines changed

5 files changed

+60
-19
lines changed

libafl_libfuzzer/libafl_libfuzzer_runtime/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ crate-type = ["staticlib", "rlib"]
2020
libafl = { path = "../../libafl", default-features = false, features = ["std", "derive", "llmp_compression", "rand_trait", "fork", "errors_backtrace"] }
2121
libafl_targets = { path = "../../libafl_targets", features = ["sancov_8bit", "sancov_cmplog", "libfuzzer", "libfuzzer_oom"] }
2222
libc = "0.2.139"
23+
log = "0.4.17"
2324
mimalloc = { version = "0.1.34", default-features = false }
2425
rand = "0.8.5"
2526
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] } # serialization lib

libafl_libfuzzer/libafl_libfuzzer_runtime/src/feedbacks.rs

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ use libafl::{
99
executors::ExitKind,
1010
feedbacks::Feedback,
1111
impl_serdeany,
12-
inputs::UsesInput,
12+
inputs::{BytesInput, Input, UsesInput},
1313
observers::ObserversTuple,
1414
state::{HasClientPerfMonitor, HasMetadata},
1515
Error,
1616
};
1717
use libafl_targets::OOMFeedback;
1818
use serde::{Deserialize, Serialize};
1919

20+
use crate::options::ArtifactPrefix;
21+
2022
#[derive(Debug)]
2123
pub struct LibfuzzerKeepFeedback {
2224
keep: Rc<RefCell<bool>>,
@@ -75,12 +77,14 @@ impl LibfuzzerCrashCauseMetadata {
7577

7678
#[derive(Debug)]
7779
pub struct LibfuzzerCrashCauseFeedback {
80+
artifact_prefix: Option<ArtifactPrefix>,
7881
exit_kind: ExitKind,
7982
}
8083

8184
impl LibfuzzerCrashCauseFeedback {
82-
pub fn new() -> Self {
85+
pub fn new(artifact_prefix: Option<ArtifactPrefix>) -> Self {
8386
Self {
87+
artifact_prefix,
8488
exit_kind: ExitKind::Ok,
8589
}
8690
}
@@ -92,9 +96,40 @@ impl Named for LibfuzzerCrashCauseFeedback {
9296
}
9397
}
9498

99+
impl LibfuzzerCrashCauseFeedback {
100+
fn set_filename<I: Input>(&self, prefix: &str, testcase: &mut Testcase<I>) {
101+
let base = if let Some(filename) = testcase.filename() {
102+
filename.clone()
103+
} else {
104+
let name = testcase.input().as_ref().unwrap().generate_name(0);
105+
name
106+
};
107+
let filename = if let Some(artifact_prefix) = self.artifact_prefix.as_ref() {
108+
if let Some(filename_prefix) = artifact_prefix.filename_prefix() {
109+
artifact_prefix
110+
.dir()
111+
.join(format!("{}{}-{}", filename_prefix, prefix, base))
112+
.to_str()
113+
.expect("Invalid filename for testcase.")
114+
.to_string()
115+
} else {
116+
artifact_prefix
117+
.dir()
118+
.join(format!("{}-{}", prefix, base))
119+
.to_str()
120+
.expect("Invalid filename for testcase.")
121+
.to_string()
122+
}
123+
} else {
124+
format!("{}-{}", prefix, base)
125+
};
126+
testcase.set_filename(filename);
127+
}
128+
}
129+
95130
impl<S> Feedback<S> for LibfuzzerCrashCauseFeedback
96131
where
97-
S: UsesInput + HasClientPerfMonitor,
132+
S: UsesInput<Input = BytesInput> + HasClientPerfMonitor,
98133
{
99134
fn is_interesting<EM, OT>(
100135
&mut self,
@@ -123,30 +158,25 @@ where
123158
{
124159
match self.exit_kind {
125160
ExitKind::Crash | ExitKind::Oom if OOMFeedback::oomed() => {
126-
if let Some(filename) = testcase.filename_mut() {
127-
*filename = format!("oom-{}", filename);
128-
}
161+
self.set_filename("oom", testcase);
129162
testcase.metadata_mut().insert(LibfuzzerCrashCauseMetadata {
130163
kind: ExitKind::Oom,
131164
});
132165
}
133-
ExitKind::Crash | ExitKind::Oom => {
134-
if let Some(filename) = testcase.filename_mut() {
135-
*filename = format!("crash-{}", filename);
136-
}
166+
ExitKind::Crash => {
167+
self.set_filename("crash", testcase);
137168
testcase.metadata_mut().insert(LibfuzzerCrashCauseMetadata {
138169
kind: ExitKind::Crash,
139170
});
140171
}
141172
ExitKind::Timeout => {
142-
if let Some(filename) = testcase.filename_mut() {
143-
*filename = format!("timeout-{}", filename);
144-
}
173+
self.set_filename("timeout", testcase);
145174
testcase.metadata_mut().insert(LibfuzzerCrashCauseMetadata {
146175
kind: ExitKind::Timeout,
147176
});
148177
}
149178
_ => {
179+
self.set_filename("uncategorized", testcase);
150180
testcase.metadata_mut().insert(LibfuzzerCrashCauseMetadata {
151181
kind: self.exit_kind,
152182
});

libafl_libfuzzer/libafl_libfuzzer_runtime/src/fuzz.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ where
4949
ExitKind::Oom if !options.ignore_ooms() => halt = true,
5050
ExitKind::Crash if !options.ignore_crashes() => halt = true,
5151
ExitKind::Timeout if !options.ignore_timeouts() => halt = true,
52-
_ => {}
52+
_ => {
53+
log::info!("Ignoring {kind:?} according to requested ignore rules.");
54+
}
5355
}
5456
if halt {
55-
eprintln!("Halting; the error on the next line is actually okay. :)");
57+
log::info!("Halting; the error on the next line is actually okay. :)");
5658
return Err(Error::shutting_down());
5759
}
5860
}

libafl_libfuzzer/libafl_libfuzzer_runtime/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ macro_rules! fuzz_with {
6161
corpus::{CachedOnDiskCorpus, Corpus, OnDiskCorpus},
6262
executors::{ExitKind, InProcessExecutor, TimeoutExecutor},
6363
feedback_and_fast, feedback_not, feedback_or, feedback_or_fast,
64-
feedbacks::{CrashFeedback, MaxMapFeedback, NewHashFeedback, TimeFeedback, TimeoutFeedback},
64+
feedbacks::{ConstFeedback, CrashFeedback, MaxMapFeedback, NewHashFeedback, TimeFeedback, TimeoutFeedback},
6565
generators::RandBytesGenerator,
6666
inputs::{BytesInput, HasTargetBytes},
6767
mutators::{
@@ -183,11 +183,11 @@ macro_rules! fuzz_with {
183183

184184
// A feedback to choose if an input is a solution or not
185185
let mut objective = feedback_or_fast!(
186-
LibfuzzerCrashCauseFeedback::new(),
186+
LibfuzzerCrashCauseFeedback::new($options.artifact_prefix().cloned()),
187187
OOMFeedback,
188188
feedback_and_fast!(
189189
CrashFeedback::new(),
190-
NewHashFeedback::new(&backtrace_observer)
190+
feedback_or_fast!(ConstFeedback::new($options.dedup()), NewHashFeedback::new(&backtrace_observer))
191191
),
192192
TimeoutFeedback::new()
193193
);

libafl_libfuzzer/libafl_libfuzzer_runtime/src/options.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ pub struct LibfuzzerOptions {
103103
ignore_timeouts: bool,
104104
ignore_ooms: bool,
105105
rss_limit: usize,
106+
malloc_limit: usize,
107+
dedup: bool,
106108
tui: bool,
107109
unknown: Vec<String>,
108-
pub malloc_limit: usize,
109110
}
110111

111112
impl LibfuzzerOptions {
@@ -178,6 +179,10 @@ impl LibfuzzerOptions {
178179
self.malloc_limit
179180
}
180181

182+
pub fn dedup(&self) -> bool {
183+
self.dedup
184+
}
185+
181186
pub fn tui(&self) -> bool {
182187
self.tui
183188
}
@@ -202,6 +207,7 @@ struct LibfuzzerOptionsBuilder<'a> {
202207
rss_limit: Option<usize>,
203208
malloc_limit: Option<usize>,
204209
ignore_remaining: bool,
210+
dedup: bool,
205211
tui: bool,
206212
unknown: Vec<&'a str>,
207213
}
@@ -279,6 +285,7 @@ impl<'a> LibfuzzerOptionsBuilder<'a> {
279285
"ignore_remaining_args" => {
280286
self.ignore_remaining = parse_or_bail!(name, value, u64) > 0
281287
}
288+
"dedup" => self.dedup = parse_or_bail!(name, value, u64) > 0,
282289
"tui" => self.tui = parse_or_bail!(name, value, u64) > 0,
283290
_ => {
284291
eprintln!("warning: unrecognised flag {name}");
@@ -316,6 +323,7 @@ impl<'a> LibfuzzerOptionsBuilder<'a> {
316323
0 => usize::MAX,
317324
value => value,
318325
},
326+
dedup: self.dedup,
319327
tui: self.tui,
320328
unknown: self.unknown.into_iter().map(|s| s.to_string()).collect(),
321329
})

0 commit comments

Comments
 (0)