From 800b85c850e9ed1dda183630125f620ddaa3f265 Mon Sep 17 00:00:00 2001 From: Stu Small Date: Mon, 29 Apr 2019 20:13:37 -0600 Subject: [PATCH] Add param parsing fuzzer and fix finding --- hfuzz/Cargo.toml | 4 ++-- hfuzz/src/bin/params.rs | 15 +++++++++++++++ src/params/patterns.rs | 6 ++++-- 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 hfuzz/src/bin/params.rs diff --git a/hfuzz/Cargo.toml b/hfuzz/Cargo.toml index 7e994f9d..c821148f 100644 --- a/hfuzz/Cargo.toml +++ b/hfuzz/Cargo.toml @@ -4,6 +4,6 @@ version = "0.1.0" authors = ["Jake McGinty "] [dependencies] -honggfuzz = { git = "https://github.com/mcginty/honggfuzz-rs", branch = "assert-unwind" } +honggfuzz = "0.5" snow = { path = "../" } -lazy_static = "*" \ No newline at end of file +lazy_static = "*" diff --git a/hfuzz/src/bin/params.rs b/hfuzz/src/bin/params.rs new file mode 100644 index 00000000..42ccbb3f --- /dev/null +++ b/hfuzz/src/bin/params.rs @@ -0,0 +1,15 @@ +#[macro_use] extern crate honggfuzz; +extern crate snow; + +fn main() { + loop { + fuzz!(|data: &[u8]| { + if let Ok(s) = String::from_utf8(data.to_vec()){ + if let Ok(p) = s.parse(){ + let builder = snow::Builder::new(p); + let _ = builder.build_initiator(); + } + } + }); + } +} \ No newline at end of file diff --git a/src/params/patterns.rs b/src/params/patterns.rs index b64b4908..2b4cb0b5 100644 --- a/src/params/patterns.rs +++ b/src/params/patterns.rs @@ -222,8 +222,10 @@ impl HandshakeChoice { fn parse_pattern_and_modifier(s: &str) -> Result<(HandshakePattern, &str), Error> { for i in (1..=4).rev() { if s.len() > i-1 { - if let Ok(p) = (&s[..i]).parse() { - return Ok((p, &s[i..])); + if s.is_char_boundary(i) { + if let Ok(p) = (&s[..i]).parse() { + return Ok((p, &s[i..])); + } } } }