From: Savil Srivastava Date: Sat, 28 Jul 2018 16:44:15 +0000 (-0700) Subject: use hex::decode instead of extend_vec_from_hex X-Git-Tag: v0.0.12~360^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=4c44b787f1ffcab8ceec47a4973915ec24ba590e;p=rust-lightning use hex::decode instead of extend_vec_from_hex --- diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 22f4bdcc1..aec5d9a81 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -16,12 +16,13 @@ afl_fuzz = ["afl"] honggfuzz_fuzz = ["honggfuzz"] [dependencies] +afl = { version = "0.3", optional = true } lightning = { path = "..", features = ["fuzztarget"] } bitcoin = { version = "0.13", features = ["fuzztarget"] } -secp256k1 = { version = "0.9", features=["fuzztarget"] } -rust-crypto = "0.2" +hex = "0.3.2" honggfuzz = { version = "0.5", optional = true } -afl = { version = "0.3", optional = true } +rust-crypto = "0.2" +secp256k1 = { version = "0.9", features=["fuzztarget"] } [build-dependencies] cc = "1.0" diff --git a/fuzz/fuzz_targets/chanmon_deser_target.rs b/fuzz/fuzz_targets/chanmon_deser_target.rs index 0bf86177a..adf4a3a6a 100644 --- a/fuzz/fuzz_targets/chanmon_deser_target.rs +++ b/fuzz/fuzz_targets/chanmon_deser_target.rs @@ -35,29 +35,12 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - fn extend_vec_from_hex(hex: &str, out: &mut Vec) { - 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; - } - } - } #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/channel_target.rs b/fuzz/fuzz_targets/channel_target.rs index 6b24d700e..683faf0ed 100644 --- a/fuzz/fuzz_targets/channel_target.rs +++ b/fuzz/fuzz_targets/channel_target.rs @@ -333,29 +333,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - fn extend_vec_from_hex(hex: &str, out: &mut Vec) { - 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; - } - } - } - #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/full_stack_target.rs b/fuzz/fuzz_targets/full_stack_target.rs index 6fdac8ad2..cf84701d4 100644 --- a/fuzz/fuzz_targets/full_stack_target.rs +++ b/fuzz/fuzz_targets/full_stack_target.rs @@ -368,29 +368,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - fn extend_vec_from_hex(hex: &str, out: &mut Vec) { - 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; - } - } - } - #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_ping_target.rs b/fuzz/fuzz_targets/msg_ping_target.rs index f2eaf0dbd..a2e0d3419 100644 --- a/fuzz/fuzz_targets/msg_ping_target.rs +++ b/fuzz/fuzz_targets/msg_ping_target.rs @@ -35,29 +35,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - fn extend_vec_from_hex(hex: &str, out: &mut Vec) { - 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; - } - } - } - #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_pong_target.rs b/fuzz/fuzz_targets/msg_pong_target.rs index 9843b79a2..a61420db7 100644 --- a/fuzz/fuzz_targets/msg_pong_target.rs +++ b/fuzz/fuzz_targets/msg_pong_target.rs @@ -35,29 +35,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - fn extend_vec_from_hex(hex: &str, out: &mut Vec) { - 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; - } - } - } - #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_targets/msg_accept_channel_target.rs b/fuzz/fuzz_targets/msg_targets/msg_accept_channel_target.rs index a0e9cc4ef..9e4b7642f 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_accept_channel_target.rs +++ b/fuzz/fuzz_targets/msg_targets/msg_accept_channel_target.rs @@ -36,13 +36,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - use utils::extend_vec_from_hex; #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_targets/msg_channel_reestablish_target.rs b/fuzz/fuzz_targets/msg_targets/msg_channel_reestablish_target.rs index dc9c2acd1..09ad367e2 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_channel_reestablish_target.rs +++ b/fuzz/fuzz_targets/msg_targets/msg_channel_reestablish_target.rs @@ -36,13 +36,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - use utils::extend_vec_from_hex; #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_targets/msg_closing_signed_target.rs b/fuzz/fuzz_targets/msg_targets/msg_closing_signed_target.rs index 621ffe2b1..7c87970ae 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_closing_signed_target.rs +++ b/fuzz/fuzz_targets/msg_targets/msg_closing_signed_target.rs @@ -36,13 +36,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - use utils::extend_vec_from_hex; #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_targets/msg_commitment_signed_target.rs b/fuzz/fuzz_targets/msg_targets/msg_commitment_signed_target.rs index e73696c8d..1ded2cfe3 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_commitment_signed_target.rs +++ b/fuzz/fuzz_targets/msg_targets/msg_commitment_signed_target.rs @@ -36,13 +36,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - use utils::extend_vec_from_hex; #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_targets/msg_error_message_target.rs b/fuzz/fuzz_targets/msg_targets/msg_error_message_target.rs index 7022786f4..8fa7de518 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_error_message_target.rs +++ b/fuzz/fuzz_targets/msg_targets/msg_error_message_target.rs @@ -36,13 +36,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - use utils::extend_vec_from_hex; #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_targets/msg_funding_created_target.rs b/fuzz/fuzz_targets/msg_targets/msg_funding_created_target.rs index f7d1a58a5..45c7c408e 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_funding_created_target.rs +++ b/fuzz/fuzz_targets/msg_targets/msg_funding_created_target.rs @@ -36,13 +36,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - use utils::extend_vec_from_hex; #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_targets/msg_funding_locked_target.rs b/fuzz/fuzz_targets/msg_targets/msg_funding_locked_target.rs index 00fdef3f8..e9e6fec55 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_funding_locked_target.rs +++ b/fuzz/fuzz_targets/msg_targets/msg_funding_locked_target.rs @@ -36,13 +36,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - use utils::extend_vec_from_hex; #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_targets/msg_funding_signed_target.rs b/fuzz/fuzz_targets/msg_targets/msg_funding_signed_target.rs index 9b66c88fe..a92e2fabb 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_funding_signed_target.rs +++ b/fuzz/fuzz_targets/msg_targets/msg_funding_signed_target.rs @@ -36,13 +36,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - use utils::extend_vec_from_hex; #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_targets/msg_open_channel_target.rs b/fuzz/fuzz_targets/msg_targets/msg_open_channel_target.rs index 8d7664f8a..7c1d6f829 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_open_channel_target.rs +++ b/fuzz/fuzz_targets/msg_targets/msg_open_channel_target.rs @@ -36,13 +36,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - use utils::extend_vec_from_hex; #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_targets/msg_revoke_and_ack_target.rs b/fuzz/fuzz_targets/msg_targets/msg_revoke_and_ack_target.rs index de7e93141..560e05b02 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_revoke_and_ack_target.rs +++ b/fuzz/fuzz_targets/msg_targets/msg_revoke_and_ack_target.rs @@ -36,13 +36,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - use utils::extend_vec_from_hex; #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_targets/msg_shutdown_target.rs b/fuzz/fuzz_targets/msg_targets/msg_shutdown_target.rs index 57e245676..5df8a3825 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_shutdown_target.rs +++ b/fuzz/fuzz_targets/msg_targets/msg_shutdown_target.rs @@ -36,13 +36,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - use utils::extend_vec_from_hex; #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_targets/msg_target_template.txt b/fuzz/fuzz_targets/msg_targets/msg_target_template.txt index 55a9761c9..f65e91f59 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_target_template.txt +++ b/fuzz/fuzz_targets/msg_targets/msg_target_template.txt @@ -36,13 +36,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - use utils::extend_vec_from_hex; #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_targets/msg_update_add_htlc_target.rs b/fuzz/fuzz_targets/msg_targets/msg_update_add_htlc_target.rs index 2a2c80701..93cdaa42c 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_update_add_htlc_target.rs +++ b/fuzz/fuzz_targets/msg_targets/msg_update_add_htlc_target.rs @@ -36,13 +36,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - use utils::extend_vec_from_hex; #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_targets/msg_update_fail_htlc_target.rs b/fuzz/fuzz_targets/msg_targets/msg_update_fail_htlc_target.rs index aca62f7bb..ffac12184 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_update_fail_htlc_target.rs +++ b/fuzz/fuzz_targets/msg_targets/msg_update_fail_htlc_target.rs @@ -36,13 +36,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - use utils::extend_vec_from_hex; #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_targets/msg_update_fail_malformed_htlc_target.rs b/fuzz/fuzz_targets/msg_targets/msg_update_fail_malformed_htlc_target.rs index e91bb3bdf..9c9099259 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_update_fail_malformed_htlc_target.rs +++ b/fuzz/fuzz_targets/msg_targets/msg_update_fail_malformed_htlc_target.rs @@ -36,13 +36,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - use utils::extend_vec_from_hex; #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_targets/msg_update_fee_target.rs b/fuzz/fuzz_targets/msg_targets/msg_update_fee_target.rs index e7488306b..4aa727126 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_update_fee_target.rs +++ b/fuzz/fuzz_targets/msg_targets/msg_update_fee_target.rs @@ -36,13 +36,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - use utils::extend_vec_from_hex; #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_targets/msg_update_fulfill_htlc_target.rs b/fuzz/fuzz_targets/msg_targets/msg_update_fulfill_htlc_target.rs index cd449908a..86e99f8c4 100644 --- a/fuzz/fuzz_targets/msg_targets/msg_update_fulfill_htlc_target.rs +++ b/fuzz/fuzz_targets/msg_targets/msg_update_fulfill_htlc_target.rs @@ -36,13 +36,11 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - use utils::extend_vec_from_hex; #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } } diff --git a/fuzz/fuzz_targets/msg_targets/utils.rs b/fuzz/fuzz_targets/msg_targets/utils.rs index 4d355585d..27de871dc 100644 --- a/fuzz/fuzz_targets/msg_targets/utils.rs +++ b/fuzz/fuzz_targets/msg_targets/utils.rs @@ -11,22 +11,3 @@ macro_rules! test_msg { } } } - -#[allow(dead_code)] -#[cfg(test)] -pub fn extend_vec_from_hex(hex: &str, out: &mut Vec) { - 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; - } - } -} diff --git a/fuzz/fuzz_targets/peer_crypt_target.rs b/fuzz/fuzz_targets/peer_crypt_target.rs index 06d00c2ec..4133331a7 100644 --- a/fuzz/fuzz_targets/peer_crypt_target.rs +++ b/fuzz/fuzz_targets/peer_crypt_target.rs @@ -99,29 +99,12 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - fn extend_vec_from_hex(hex: &str, out: &mut Vec) { - 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; - } - } - } #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("01", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("01").unwrap()); } } diff --git a/fuzz/fuzz_targets/router_target.rs b/fuzz/fuzz_targets/router_target.rs index 13733adb6..ed4737221 100644 --- a/fuzz/fuzz_targets/router_target.rs +++ b/fuzz/fuzz_targets/router_target.rs @@ -191,29 +191,12 @@ fn main() { } } +extern crate hex; #[cfg(test)] mod tests { - fn extend_vec_from_hex(hex: &str, out: &mut Vec) { - 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; - } - } - } #[test] fn duplicate_crash() { - let mut a = Vec::new(); - extend_vec_from_hex("00", &mut a); - super::do_test(&a); + super::do_test(&::hex::decode("00").unwrap()); } }