Skip to content

Commit

Permalink
fuzz: add a fuzz target for descriptor parsing
Browse files Browse the repository at this point in the history
Co-Authored-By: Andrew Poelstra <apoelstra@wpsoftware.net>
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
  • Loading branch information
darosior and apoelstra committed Oct 1, 2020
1 parent 5ac4112 commit 28158a3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
6 changes: 5 additions & 1 deletion fuzz/Cargo.toml
Expand Up @@ -43,4 +43,8 @@ path = "fuzz_targets/roundtrip_semantic.rs"

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

[[bin]]
name = "parse_descriptor"
path = "fuzz_targets/parse_descriptor.rs"
33 changes: 33 additions & 0 deletions fuzz/fuzz_targets/parse_descriptor.rs
@@ -0,0 +1,33 @@
extern crate miniscript;

use miniscript::descriptor::DescriptorPublicKey;
use std::str::FromStr;

fn do_test(data: &[u8]) {
let data_str = String::from_utf8_lossy(data);
if let Ok(dpk) = DescriptorPublicKey::from_str(&data_str) {
let output = dpk.to_string();
assert_eq!(data_str.to_lowercase(), output.to_lowercase());
}
}

#[cfg(feature = "afl")]
extern crate afl;
#[cfg(feature = "afl")]
fn main() {
afl::read_stdio_bytes(|data| {
do_test(&data);
});
}

#[cfg(feature = "honggfuzz")]
#[macro_use]
extern crate honggfuzz;
#[cfg(feature = "honggfuzz")]
fn main() {
loop {
fuzz!(|data| {
do_test(data);
});
}
}

0 comments on commit 28158a3

Please sign in to comment.