Macro hongg::fuzz

source ·
macro_rules! fuzz {
    (|$buf:ident| $body:block) => { ... };
    (|$buf:ident: &[u8]| $body:block) => { ... };
    (|$buf:ident: $dty:ty| $body:block) => { ... };
}
Expand description

Fuzz a closure-like block of code by passing it an object of arbitrary type.

You can choose the type of the argument using the syntax as in the example below. Please check out the arbitrary crate to see which types are available.

For performance reasons, it is recommended that you use the native type &[u8] when possible.

For perstistent fuzzing to work, you have to call it ad vita aeternam in an infinite loop.

loop {
    fuzz!(|data: &[u8]| {
        if data.len() != 3 {return}
        if data[0] != b'h' {return}
        if data[1] != b'e' {return}
        if data[2] != b'y' {return}
        panic!("BOOM")
    });
}