Coverage Report

Created: 2025-02-25 06:39

/src/ztunnel/fuzz/fuzz_targets/baggage.rs
Line
Count
Source
1
// Copyright Istio Authors
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#![no_main]
16
17
use hyper::{http::HeaderValue, HeaderMap};
18
use libfuzzer_sys::fuzz_target;
19
use ztunnel::baggage::parse_baggage_header;
20
use ztunnel::proxy::BAGGAGE_HEADER;
21
22
fuzz_target!(|data: &[u8]| {
23
    let _ = run_baggage_header_parser(data);
24
    let _ = run_forwarded_header_parser(data);
25
});
26
27
1.42k
fn run_baggage_header_parser(data: &[u8]) -> anyhow::Result<()> {
28
1.42k
    let mut hm = HeaderMap::new();
29
1.42k
    hm.append(BAGGAGE_HEADER, HeaderValue::from_bytes(data)?);
30
1.15k
    parse_baggage_header(hm.get_all(BAGGAGE_HEADER))?;
31
1.07k
    Ok(())
32
1.42k
}
33
34
1.42k
fn run_forwarded_header_parser(data: &[u8]) -> anyhow::Result<()> {
35
1.42k
    let s = std::str::from_utf8(data)?;
36
1.36k
    let _ = ztunnel::proxy::parse_forwarded_host(s);
37
1.36k
    Ok(())
38
1.42k
}