Skip to content

Commit

Permalink
build: Add AFL++ fuzzing support (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
anfedotoff authored Mar 27, 2023
1 parent d7e8e29 commit 9449f03
Show file tree
Hide file tree
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 <fedotoff@ispras.ru>"]
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
Expand Up @@ -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 {}
Expand Down

0 comments on commit 9449f03

Please sign in to comment.