Stack hash.

This commit is contained in:
Sergey Pepyakin 2018-03-25 13:28:01 +03:00
parent 959503b49d
commit 52ed4bb589
1 changed files with 21 additions and 7 deletions

View File

@ -8,7 +8,12 @@ use std::fs::File;
use std::io::Write; use std::io::Write;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
fn run_spec(data: &[u8]) -> Result<(), ()> { fn dump_all_into_buf(src: &[u8], buf: &mut [u8; 64]) {
let common_len = usize::min(src.len(), buf.len());
buf[0..common_len].copy_from_slice(&src[0..common_len]);
}
fn run_spec(data: &[u8], stdout_msg_buf: &mut [u8; 64], stderr_msg_buf: &mut [u8; 64]) -> Result<(), ()> {
let temp_dir = tempdir::TempDir::new("spec").unwrap(); let temp_dir = tempdir::TempDir::new("spec").unwrap();
let mut seed_path = temp_dir.path().to_path_buf(); let mut seed_path = temp_dir.path().to_path_buf();
seed_path.push("test.wasm"); seed_path.push("test.wasm");
@ -24,17 +29,19 @@ fn run_spec(data: &[u8]) -> Result<(), ()> {
); );
} }
let exit_status = Command::new("wasm") let output = Command::new("wasm")
.arg("-d") .arg("-d")
.arg(&seed_path) .arg(&seed_path)
.stdout(Stdio::null()) .stdout(Stdio::null())
.stderr(Stdio::null()) .stderr(Stdio::null())
.status() .output()
.expect("failed to execute `wasm`"); .expect("failed to execute `wasm`");
if exit_status.success() { if output.status.success() {
Ok(()) Ok(())
} else { } else {
dump_all_into_buf(&output.stdout, stdout_msg_buf);
dump_all_into_buf(&output.stderr, stderr_msg_buf);
Err(()) Err(())
} }
} }
@ -47,10 +54,17 @@ fn run_wasmi(data: &[u8]) -> Result<(), ()> {
fn main() { fn main() {
loop { loop {
fuzz!(|data: &[u8]| { fuzz!(|data: &[u8]| {
let wasmi_result = run_wasmi(data); // Keep messages on stack. This should lead to a different stack hashes for
let wasm_result = run_spec(data); // different error messages.
let mut stdout_msg_buf: [u8; 64] = [0; 64];
let mut stderr_msg_buf: [u8; 64] = [0; 64];
assert_eq!(wasmi_result.is_ok(), wasm_result.is_ok()); let wasmi_result = run_wasmi(data);
let wasm_result = run_spec(data, &mut stdout_msg_buf, &mut stderr_msg_buf);
if wasmi_result.is_ok() != wasm_result.is_ok() {
panic!("stdout: {:?}, stderr: {:?}", &stdout_msg_buf[..], &stderr_msg_buf as &[u8]);
}
}); });
} }
} }