Files

48 lines
1.5 KiB
Rust
Raw Permalink Normal View History

// This file is part of the uutils coreutils package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
2023-02-18 21:44:24 +01:00
#![no_main]
2023-02-18 21:44:24 +01:00
use libfuzzer_sys::fuzz_target;
use std::ffi::OsString;
use uu_date::uumain;
2025-11-02 21:48:49 +01:00
use uufuzz::generate_and_run_uumain;
2023-02-18 21:44:24 +01:00
fuzz_target!(|data: &[u8]| {
2023-03-07 13:40:59 +01:00
let delim: u8 = 0; // Null byte
2025-11-02 23:16:55 +01:00
let fuzz_args: Vec<OsString> = data
2023-03-07 13:40:59 +01:00
.split(|b| *b == delim)
.filter_map(|e| std::str::from_utf8(e).ok())
2025-11-02 21:48:49 +01:00
.map(OsString::from)
.collect();
2025-11-02 23:16:55 +01:00
// Skip test cases that would cause the program to read from stdin
// These would hang the fuzzer waiting for input
for i in 0..fuzz_args.len() {
if let Some(arg) = fuzz_args.get(i) {
let arg_str = arg.to_string_lossy();
// Skip if -f- or --file=- or combined options like -Rf- (reads dates from stdin)
if (arg_str.starts_with('-') && !arg_str.starts_with("--") && arg_str.ends_with("f-"))
|| (arg_str == "-f"
&& fuzz_args
.get(i + 1)
.map(|a| a.to_string_lossy() == "-")
.unwrap_or(false))
2025-11-02 23:16:55 +01:00
|| arg_str == "-f-"
|| arg_str == "--file=-"
{
return;
}
}
2025-11-02 21:48:49 +01:00
}
2025-11-02 23:16:55 +01:00
// Add program name as first argument (required for proper argument parsing)
let mut args = vec![OsString::from("date")];
args.extend(fuzz_args);
let _ = generate_and_run_uumain(&args, uumain, None);
2023-02-18 21:44:24 +01:00
});