aboutsummaryrefslogtreecommitdiff
path: root/crates/tor-netdoc/fuzz/fuzz_targets/hsdesc.rs
blob: f9a2fd78cfa06b97c0fc0669fa300c92190da4fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#![no_main]
use libfuzzer_sys::fuzz_target;
use tor_netdoc::doc::hsdesc::{HsDescInner, HsDescMiddle, HsDescOuter};

fuzz_target!(|data: &[u8]| {
    if data.len() > 0 {
        if let Ok(s) = std::str::from_utf8(&data[1..]) {
            match data[0] % 3 {
                0 => {
                    let _ = HsDescInner::parse(s);
                }
                1 => {
                    let _ = HsDescMiddle::parse(s);
                }
                2 => {
                    let _ = HsDescOuter::parse(s);
                }
                _ => panic!("uh oh, math broke"),
            }
        }
    }
});