Skip to content

Commit

Permalink
Add more cargo-fuzz targets (#143)
Browse files Browse the repository at this point in the history
* cargo-fuzz: add new target to parse responses

Add a new cargo-fuzz target to test the Response parsing code.

* cargo-fuzz: add new targets with relaxed multiple space options

Add two new targets to fuzz parsing requests and responses with
multiple spaces enabled via ParserConfig.
  • Loading branch information
00xc authored May 24, 2023
1 parent 46c9c9b commit 9ef6d3e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
18 changes: 18 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,21 @@ name = "parse_headers"
path = "fuzz_targets/parse_headers.rs"
test = false
doc = false

[[bin]]
name = "parse_response"
path = "fuzz_targets/parse_response.rs"
test = false
doc = false

[[bin]]
name = "parse_response_multspaces"
path = "fuzz_targets/parse_response_multspaces.rs"
test = false
doc = false

[[bin]]
name = "parse_request_multspaces"
path = "fuzz_targets/parse_request_multspaces.rs"
test = false
doc = false
11 changes: 11 additions & 0 deletions fuzz/fuzz_targets/parse_request_multspaces.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![no_main]

use libfuzzer_sys::fuzz_target;

fuzz_target!(|data: &[u8]| {
let mut headers = [httparse::EMPTY_HEADER; 16];
let mut resp = httparse::Request::new(&mut headers);
let _ = httparse::ParserConfig::default()
.allow_multiple_spaces_in_request_line_delimiters(true)
.parse_request(&mut resp, data);
});
8 changes: 8 additions & 0 deletions fuzz/fuzz_targets/parse_response.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![no_main]
use libfuzzer_sys::fuzz_target;

fuzz_target!(|data: &[u8]| {
let mut headers = [httparse::EMPTY_HEADER; 16];
let mut resp = httparse::Response::new(&mut headers);
let _ = resp.parse(data);
});
11 changes: 11 additions & 0 deletions fuzz/fuzz_targets/parse_response_multspaces.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![no_main]

use libfuzzer_sys::fuzz_target;

fuzz_target!(|data: &[u8]| {
let mut headers = [httparse::EMPTY_HEADER; 16];
let mut resp = httparse::Response::new(&mut headers);
let _ = httparse::ParserConfig::default()
.allow_multiple_spaces_in_response_status_delimiters(true)
.parse_response(&mut resp, data);
});

0 comments on commit 9ef6d3e

Please sign in to comment.