Fixed issues with fuzz in core. (#3193)

* Include ser::ProtocolVersion in fuzz generator.
* Adjusted block_read_v1's path to appropriate file.
This commit is contained in:
mplsgrant 2020-01-21 04:03:24 -06:00 committed by hashmap
parent 6e5afe496b
commit da3b3b23c6
2 changed files with 33 additions and 6 deletions

View file

@ -31,7 +31,7 @@ path = "src/main.rs"
[[bin]] [[bin]]
name = "block_read_v1" name = "block_read_v1"
path = "fuzz_targets/block_read_v2.rs" path = "fuzz_targets/block_read_v1.rs"
[[bin]] [[bin]]
name = "block_read_v2" name = "block_read_v2"

View file

@ -7,12 +7,39 @@ use std::fs::{self, File};
use std::path::Path; use std::path::Path;
fn main() { fn main() {
generate("transaction_read", Transaction::default()).unwrap(); generate(
generate("block_read", Block::default()).unwrap(); "transaction_read_v1",
generate("compact_block_read", CompactBlock::from(Block::default())).unwrap(); ser::ProtocolVersion(1),
Transaction::default(),
)
.unwrap();
generate("block_read_v1", ser::ProtocolVersion(1), Block::default()).unwrap();
generate(
"compact_block_read_v1",
ser::ProtocolVersion(1),
CompactBlock::from(Block::default()),
)
.unwrap();
generate(
"transaction_read_v2",
ser::ProtocolVersion(2),
Transaction::default(),
)
.unwrap();
generate("block_read_v2", ser::ProtocolVersion(2), Block::default()).unwrap();
generate(
"compact_block_read_v2",
ser::ProtocolVersion(2),
CompactBlock::from(Block::default()),
)
.unwrap();
} }
fn generate<W: ser::Writeable>(target: &str, obj: W) -> Result<(), ser::Error> { fn generate<W: ser::Writeable>(
target: &str,
version: ser::ProtocolVersion,
obj: W,
) -> Result<(), ser::Error> {
let dir_path = Path::new("corpus").join(target); let dir_path = Path::new("corpus").join(target);
if !dir_path.is_dir() { if !dir_path.is_dir() {
fs::create_dir_all(&dir_path).map_err(|e| { fs::create_dir_all(&dir_path).map_err(|e| {
@ -25,7 +52,7 @@ fn generate<W: ser::Writeable>(target: &str, obj: W) -> Result<(), ser::Error> {
if !pattern_path.exists() { if !pattern_path.exists() {
let mut file = File::create(&pattern_path) let mut file = File::create(&pattern_path)
.map_err(|e| ser::Error::IOErr("can't create a pattern file".to_owned(), e.kind()))?; .map_err(|e| ser::Error::IOErr("can't create a pattern file".to_owned(), e.kind()))?;
ser::serialize(&mut file, &obj) ser::serialize(&mut file, version, &obj)
} else { } else {
Ok(()) Ok(())
} }