wayver's git archive


a simple self-hosted git server
git clone https://git.wayver.dev/bile

fuzz/src/main.rs@363f1b706491794c3359d55e1dda10fb104d5344

raw
Date Commit Message Author Files + -
2026-02-18 07:55 some fixes to fuzzing wayverd 5 511 608
...

1use axum::{
2    body::{self, Body},
3    http::{Request, StatusCode},
4};
5use http_body_util::BodyExt as _;
6use tower::util::ServiceExt as _;
7
8fn main() {
9    afl::fuzz!(|data: &[u8]| {
10        if let Ok(s) = std::str::from_utf8(data) {
11            if let Ok(uri) = http::Uri::try_from(s) {
12                let Ok(rt) = tokio::runtime::Runtime::new() else {
13                    println!("failed to create tokio runtime");
14                    return;
15                };
16
17                rt.block_on(async {
18                    let Ok(req) = Request::builder().uri(uri).body(Body::empty()) else {
19                        println!("failed to create http request");
20                        return;
21                    };
22
23                    let bile =
24                        bile::Bile::init(bile::config::Config::default().finalize().unwrap());
25
26                    let Ok(res) = bile.routes().oneshot(req).await else {
27                        println!("failed to send http request");
28                        return;
29                    };
30
31                    let status = res.status();
32
33                    let body = body::to_bytes(res.into_body(), usize::MAX)
34                        .await
35                        .ok()
36                        .and_then(|bytes| String::from_utf8(bytes.to_vec()).ok())
37                        .unwrap_or_else(|| "BODY PARSE ERROR".to_string());
38
39                    assert_ne!(status, StatusCode::INTERNAL_SERVER_ERROR, "{}", body);
40                });
41            }
42        }
43    });
44}
45