Coverage Report

Created: 2025-08-26 07:09

/src/h2/fuzz/fuzz_targets/fuzz_client.rs
Line
Count
Source (jump to first uncovered line)
1
#![no_main]
2
use h2_support::prelude::*;
3
use libfuzzer_sys::{arbitrary::Arbitrary, fuzz_target};
4
5
9.40k
#[derive(Debug, Arbitrary)]
Unexecuted instantiation: <fuzz_client::HttpSpec as arbitrary::Arbitrary>::arbitrary::{closure#0}
<fuzz_client::HttpSpec as arbitrary::Arbitrary>::arbitrary_take_rest::{closure#0}
Line
Count
Source
5
4.70k
#[derive(Debug, Arbitrary)]
<fuzz_client::HttpSpec as arbitrary::Arbitrary>::try_size_hint::{closure#0}
Line
Count
Source
5
4.70k
#[derive(Debug, Arbitrary)]
6
struct HttpSpec {
7
    uri: Vec<u8>,
8
    header_name: Vec<u8>,
9
    header_value: Vec<u8>,
10
}
11
12
4.70k
async fn fuzz_entry(inp: HttpSpec) {
13
4.70k
    if let Ok(req) = Request::builder()
14
4.70k
        .uri(&inp.uri[..])
15
4.70k
        .header(&inp.header_name[..], &inp.header_value[..])
16
4.70k
        .body(())
17
    {
18
445
        let (io, mut _srv) = mock::new();
19
445
        let (mut client, _h2) = client::Builder::new()
20
445
            .handshake::<_, Bytes>(io)
21
0
            .await
22
445
            .unwrap();
23
445
24
445
        // this could still trigger a user error:
25
445
        // - if the uri isn't absolute
26
445
        // - if the header name isn't allowed in http2 (like connection)
27
445
        let _ = client.send_request(req, true);
28
4.25k
    }
29
4.70k
}
30
31
fuzz_target!(|inp: HttpSpec| {
32
    let rt = tokio::runtime::Runtime::new().unwrap();
33
    rt.block_on(fuzz_entry(inp));
34
});