Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AFL++ fuzzing support
Browse files Browse the repository at this point in the history
anfedotoff committed Mar 20, 2023
1 parent d7e8e29 commit 87c976d
Showing 4 changed files with 62 additions and 1 deletion.
27 changes: 27 additions & 0 deletions fuzz-afl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "goblin-fuzz-afl"
version = "0.0.1"
authors = ["Andrey Fedotov <[email protected]>"]
edition = "2018"
publish = false

[dependencies.goblin]
path = ".."

[dependencies]
afl = "*"

# Prevent this from interfering with workspaces
[workspace]
members = ["."]

[profile.release]
debug = true

[[bin]]
name = "afl_parse"
path = "fuzz_targets/afl_parse.rs"

[[bin]]
name = "afl_parse_elf"
path = "fuzz_targets/afl_parse_elf.rs"
8 changes: 8 additions & 0 deletions fuzz-afl/fuzz_targets/afl_parse.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[macro_use]
extern crate afl;

fn main() {
fuzz!(|data: &[u8]| {
let _ = goblin::Object::parse(data);
});
}
26 changes: 26 additions & 0 deletions fuzz-afl/fuzz_targets/afl_parse_elf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#[macro_use]
extern crate afl;

fn main() {
fuzz!(|data: &[u8]| {
if let Ok(elf) = goblin::elf::Elf::parse(data) {
for section_header in &elf.section_headers {
let _ = elf.shdr_strtab.get_at(section_header.sh_name);
}

for _relocation in &elf.dynrels {}

if let Some(mut it) = elf.iter_note_headers(data) {
while let Some(Ok(_a)) = it.next() {}
}

if let Some(mut it) = elf.iter_note_sections(data, None) {
while let Some(Ok(_a)) = it.next() {}
}

if let Some(mut it) = elf.iter_note_sections(data, Some("x")) {
while let Some(Ok(_a)) = it.next() {}
}
}
});
}
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/parse_elf.rs
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ use libfuzzer_sys::fuzz_target;
fuzz_target!(|data: &[u8]| {
if let Ok(elf) = goblin::elf::Elf::parse(data) {
for section_header in &elf.section_headers {
let _ = elf.shdr_strtab.get(section_header.sh_name);
let _ = elf.shdr_strtab.get_at(section_header.sh_name);
}

for _relocation in &elf.dynrels {}

0 comments on commit 87c976d

Please sign in to comment.