fuzz: disable tests unless 'cfg(fuzzing)' is passed; update README for reproducing failures
This commit is contained in:
parent
6e2ee5be66
commit
6467728202
|
@ -65,4 +65,29 @@ If it is working, you will see a rapid stream of data for many seconds
|
|||
(you can hit Ctrl+C to stop it early). If not, you should quickly see
|
||||
an error.
|
||||
|
||||
# Reproducing Failures
|
||||
|
||||
If a fuzztest fails, it will exit with a summary which looks something like
|
||||
|
||||
```
|
||||
...
|
||||
fuzzTarget : hfuzz_target/x86_64-unknown-linux-gnu/release/hashes_sha256
|
||||
CRASH:
|
||||
DESCRIPTION:
|
||||
ORIG_FNAME: 00000000000000000000000000000000.00000000.honggfuzz.cov
|
||||
FUZZ_FNAME: hfuzz_workspace/hashes_sha256/SIGABRT.PC.7ffff7c8abc7.STACK.18826d9b64.CODE.-6.ADDR.0.INSTR.mov____%eax,%ebp.fuzz
|
||||
...
|
||||
=====================================================================
|
||||
fff400610004
|
||||
```
|
||||
|
||||
The final line is a hex-encoded version of the input that caused the crash. You
|
||||
can test this directly by editing the `duplicate_crash` test to copy/paste the
|
||||
hex output into the call to `extend_vec_from_hex`. Then run the test with
|
||||
|
||||
RUSTFLAGS=--cfg=fuzzing cargo test
|
||||
|
||||
It is important to add the `cfg=fuzzing` flag, which tells rustc to compile the
|
||||
library as though it were running a fuzztest. In particular, this will disable
|
||||
or weaken all the cryptography.
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, fuzzing))]
|
||||
mod tests {
|
||||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
|
||||
let mut b = 0;
|
||||
|
|
|
@ -19,7 +19,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, fuzzing))]
|
||||
mod tests {
|
||||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
|
||||
let mut b = 0;
|
||||
|
|
|
@ -36,7 +36,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, fuzzing))]
|
||||
mod tests {
|
||||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
|
||||
let mut b = 0;
|
||||
|
|
|
@ -13,7 +13,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, fuzzing))]
|
||||
mod tests {
|
||||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
|
||||
let mut b = 0;
|
||||
|
|
|
@ -22,7 +22,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, fuzzing))]
|
||||
mod tests {
|
||||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
|
||||
let mut b = 0;
|
||||
|
|
|
@ -22,7 +22,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, fuzzing))]
|
||||
mod tests {
|
||||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
|
||||
let mut b = 0;
|
||||
|
|
|
@ -52,7 +52,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, fuzzing))]
|
||||
mod tests {
|
||||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
|
||||
let mut b = 0;
|
||||
|
|
|
@ -34,7 +34,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, fuzzing))]
|
||||
mod tests {
|
||||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
|
||||
let mut b = 0;
|
||||
|
|
|
@ -18,7 +18,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, fuzzing))]
|
||||
mod tests {
|
||||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
|
||||
let mut b = 0;
|
||||
|
|
|
@ -49,7 +49,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, fuzzing))]
|
||||
mod tests {
|
||||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
|
||||
let mut b = 0;
|
||||
|
|
|
@ -23,3 +23,30 @@ fn main() {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(test, fuzzing))]
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duplicate_crash() {
|
||||
let mut a = Vec::new();
|
||||
extend_vec_from_hex("00000", &mut a);
|
||||
super::do_test(&a);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, fuzzing))]
|
||||
mod tests {
|
||||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
|
||||
let mut b = 0;
|
||||
|
|
|
@ -28,7 +28,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, fuzzing))]
|
||||
mod tests {
|
||||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
|
||||
let mut b = 0;
|
||||
|
|
|
@ -20,7 +20,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, fuzzing))]
|
||||
mod tests {
|
||||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
|
||||
let mut b = 0;
|
||||
|
|
|
@ -20,7 +20,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, fuzzing))]
|
||||
mod tests {
|
||||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
|
||||
let mut b = 0;
|
||||
|
|
|
@ -20,7 +20,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, fuzzing))]
|
||||
mod tests {
|
||||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
|
||||
let mut b = 0;
|
||||
|
@ -42,7 +42,7 @@ mod tests {
|
|||
#[test]
|
||||
fn duplicate_crash() {
|
||||
let mut a = Vec::new();
|
||||
extend_vec_from_hex("00000", &mut a);
|
||||
extend_vec_from_hex("fff400610004", &mut a);
|
||||
super::do_test(&a);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, fuzzing))]
|
||||
mod tests {
|
||||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
|
||||
let mut b = 0;
|
||||
|
|
|
@ -20,7 +20,7 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(all(test, fuzzing))]
|
||||
mod tests {
|
||||
fn extend_vec_from_hex(hex: &str, out: &mut Vec<u8>) {
|
||||
let mut b = 0;
|
||||
|
|
Loading…
Reference in New Issue