Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@ git = "https://github.com/rust-fuzz/libfuzzer-sys.git"
members = ["."]

[[bin]]
name = "fuzz_target_1"
path = "fuzz_targets/fuzz_target_1.rs"
name = "fuzz_parse"
path = "fuzz_targets/fuzz_parse.rs"

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

#[macro_use] extern crate libfuzzer_sys;
extern crate httpdate;

use httpdate::HttpDate;
use std::time::{SystemTime, UNIX_EPOCH};
use std::convert::TryInto;

fuzz_target!(|data: &[u8]| {
// Skip this round if data is not enough
if data.len() < 8 {
return;
}

// Create system time object
let secs_since_epoch = u64::from_le_bytes(data[0..8].try_into().unwrap_or_default());
let duration = std::time::Duration::from_secs(secs_since_epoch);
let system_time = match UNIX_EPOCH.checked_add(duration) {
Some(time) => time,
None => return,
};

// Skip value that could make HttpDate panic
if secs_since_epoch >= 253402300800 {
return;
}

// Fuzz other functions
let http_date = HttpDate::from(system_time);
let _ = SystemTime::from(http_date);
let _ = http_date.to_string();

// Fuzz partial_cmp if enough data is left
if data.len() >= 16 {
let other_secs_since_epoch = u64::from_le_bytes(data[8..16].try_into().unwrap_or_default());
let other_duration = std::time::Duration::from_secs(other_secs_since_epoch);
let other_system_time = match UNIX_EPOCH.checked_add(other_duration) {
Some(time) => time,
None => return,
};

// Skip value that could make HttpDate panic
if other_secs_since_epoch >= 253402300800 {
return;
}

let other_http_date = HttpDate::from(other_system_time);
let _ = http_date.partial_cmp(&other_http_date);
}
});
File renamed without changes.
Loading