Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 3 additions & 16 deletions fuzz/fuzz_targets/roundtrip_concrete.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

extern crate miniscript;

#[path = "../src/util.rs"] mod util;

use std::str::FromStr;
use miniscript::{policy, DummyKey};

Expand Down Expand Up @@ -36,22 +38,7 @@ fn main() {

#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'...b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
use util::extend_vec_from_hex;

#[test]
fn duplicate_crash() {
Expand Down
20 changes: 3 additions & 17 deletions fuzz/fuzz_targets/roundtrip_descriptor.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

extern crate miniscript;

use miniscript::{Descriptor, DummyKey};
#[path = "../src/util.rs"] mod util;

use miniscript::{Descriptor, DummyKey};
use std::str::FromStr;

fn do_test(data: &[u8]) {
Expand Down Expand Up @@ -36,22 +37,7 @@ fn main() {

#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'...b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
use util::extend_vec_from_hex;

#[test]
fn duplicate_crash() {
Expand Down
19 changes: 3 additions & 16 deletions fuzz/fuzz_targets/roundtrip_miniscript_script.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

extern crate miniscript;

#[path = "../src/util.rs"] mod util;

use miniscript::Miniscript;
use miniscript::bitcoin::blockdata::script;

Expand Down Expand Up @@ -37,22 +39,7 @@ fn main() {

#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'...b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
use util::extend_vec_from_hex;

#[test]
fn duplicate_crash() {
Expand Down
20 changes: 3 additions & 17 deletions fuzz/fuzz_targets/roundtrip_miniscript_str.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

extern crate miniscript;

use std::str::FromStr;
#[path = "../src/util.rs"] mod util;

use std::str::FromStr;
use miniscript::{DummyKey};
use miniscript::Miniscript;

Expand Down Expand Up @@ -36,22 +37,7 @@ fn main() {

#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'...b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
use util::extend_vec_from_hex;

#[test]
fn duplicate_crash() {
Expand Down
26 changes: 3 additions & 23 deletions fuzz/fuzz_targets/roundtrip_policy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

extern crate miniscript;

#[path = "../src/util.rs"] mod util;

use std::str::FromStr;
use miniscript::{policy, DummyKey};

Expand Down Expand Up @@ -41,34 +43,12 @@ fn main() {

#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'...b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
use util::extend_vec_from_hex;

#[test]
fn duplicate_crash() {
let mut a = Vec::new();
extend_vec_from_hex("00", &mut a);
super::do_test(&a);
}

#[test]
fn duplicate_crash_2() {
let mut a = Vec::new();
extend_vec_from_hex("746872657368", &mut a); // thresh
super::do_test(&a);
}
}
23 changes: 5 additions & 18 deletions fuzz/fuzz_targets/roundtrip_semantic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

extern crate miniscript;

#[path = "../src/util.rs"] mod util;

use std::str::FromStr;
use miniscript::{policy, DummyKey};

Expand Down Expand Up @@ -36,27 +38,12 @@ fn main() {

#[cfg(test)]
mod tests {
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'...b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}

use util::extend_vec_from_hex;

#[test]
fn duplicate_crash() {
let mut a = Vec::new();
extend_vec_from_hex("048531e80700ae6400670000af5168", &mut a);
super::do_test(&a);
}
}
}
17 changes: 17 additions & 0 deletions fuzz/src/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#[cfg(test)]
pub fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
let mut b = 0;
for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4;
match *c {
b'A'...b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0',
_ => panic!("Bad hex"),
}
if (idx & 1) == 1 {
out.push(b);
b = 0;
}
}
}
5 changes: 5 additions & 0 deletions src/policy/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,11 @@ mod tests {
)"
)
.is_ok());

assert_eq!(
StringPolicy::from_str("thresh").unwrap_err().to_string(),
"unexpected «thresh without args»"
);
}

#[test]
Expand Down