rust-fuzz / honggfuzz-rs

Fuzz your Rust code with Google-developed Honggfuzz !
https://crates.io/crates/honggfuzz
Apache License 2.0
449 stars 40 forks source link

Missing `extern crate arbitrary` error #13

Closed abonander closed 5 years ago

abonander commented 5 years ago

The fuzz!() macro uses items from the arbitrary crate but does not declare extern crate arbitrary (it probably needs to be pub extern crate arbitrary for the macro to use it). The arbitrary crate should be added to this crate's dependencies and then imports from arbitrary can be prefixed by the $crate metavar (references to honggfuzz should be replaced with $crate as well or else if the user renames it with extern crate honggfuzz as ... then it will not be found).

Fixed fuzz!() macro:

macro_rules! fuzz {
    (|$buf:ident| $body:block) => {
        $crate::fuzz(|$buf| $body);
    };
    (|$buf:ident: &[u8]| $body:block) => {
        $crate::fuzz(|$buf| $body);
    };
    (|$buf:ident: $dty: ty| $body:block) => {
        $crate::fuzz(|$buf| {
            let $buf: $dty = {
                use $crate::arbitrary::{Arbitrary, RingBuffer};
                if let Ok(d) = RingBuffer::new($buf, $buf.len()).and_then(|mut b|{
                        Arbitrary::arbitrary(&mut b).map_err(|_| "")
                    }) {
                    d
                } else {
                    return
                }
            };

            $body
        });
    };
}
ghost commented 5 years ago

This and compatibility with version 0.2 of arbitrary is resolved by #15

PaulGrandperrin commented 5 years ago

closed by #15