Skip to content

Commit 9449f03

Browse files
authored
build: Add AFL++ fuzzing support (#351)
1 parent d7e8e29 commit 9449f03

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

Diff for: fuzz-afl/Cargo.toml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[package]
2+
name = "goblin-fuzz-afl"
3+
version = "0.0.1"
4+
authors = ["Andrey Fedotov <[email protected]>"]
5+
edition = "2018"
6+
publish = false
7+
8+
[dependencies.goblin]
9+
path = ".."
10+
11+
[dependencies]
12+
afl = "*"
13+
14+
# Prevent this from interfering with workspaces
15+
[workspace]
16+
members = ["."]
17+
18+
[profile.release]
19+
debug = true
20+
21+
[[bin]]
22+
name = "afl_parse"
23+
path = "fuzz_targets/afl_parse.rs"
24+
25+
[[bin]]
26+
name = "afl_parse_elf"
27+
path = "fuzz_targets/afl_parse_elf.rs"

Diff for: fuzz-afl/fuzz_targets/afl_parse.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[macro_use]
2+
extern crate afl;
3+
4+
fn main() {
5+
fuzz!(|data: &[u8]| {
6+
let _ = goblin::Object::parse(data);
7+
});
8+
}

Diff for: fuzz-afl/fuzz_targets/afl_parse_elf.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#[macro_use]
2+
extern crate afl;
3+
4+
fn main() {
5+
fuzz!(|data: &[u8]| {
6+
if let Ok(elf) = goblin::elf::Elf::parse(data) {
7+
for section_header in &elf.section_headers {
8+
let _ = elf.shdr_strtab.get_at(section_header.sh_name);
9+
}
10+
11+
for _relocation in &elf.dynrels {}
12+
13+
if let Some(mut it) = elf.iter_note_headers(data) {
14+
while let Some(Ok(_a)) = it.next() {}
15+
}
16+
17+
if let Some(mut it) = elf.iter_note_sections(data, None) {
18+
while let Some(Ok(_a)) = it.next() {}
19+
}
20+
21+
if let Some(mut it) = elf.iter_note_sections(data, Some("x")) {
22+
while let Some(Ok(_a)) = it.next() {}
23+
}
24+
}
25+
});
26+
}

Diff for: fuzz/fuzz_targets/parse_elf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use libfuzzer_sys::fuzz_target;
44
fuzz_target!(|data: &[u8]| {
55
if let Ok(elf) = goblin::elf::Elf::parse(data) {
66
for section_header in &elf.section_headers {
7-
let _ = elf.shdr_strtab.get(section_header.sh_name);
7+
let _ = elf.shdr_strtab.get_at(section_header.sh_name);
88
}
99

1010
for _relocation in &elf.dynrels {}

0 commit comments

Comments
 (0)