mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
date: handle the empty arguments
This commit is contained in:
@@ -3,12 +3,24 @@ use libfuzzer_sys::fuzz_target;
|
||||
|
||||
use std::ffi::OsString;
|
||||
use uu_date::uumain;
|
||||
use uufuzz::generate_and_run_uumain;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let delim: u8 = 0; // Null byte
|
||||
let args = data
|
||||
let args: Vec<OsString> = data
|
||||
.split(|b| *b == delim)
|
||||
.filter_map(|e| std::str::from_utf8(e).ok())
|
||||
.map(OsString::from);
|
||||
uumain(args);
|
||||
.map(OsString::from)
|
||||
.collect();
|
||||
|
||||
// Ensure we have at least a program name
|
||||
if args.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let date_main = |args: std::vec::IntoIter<OsString>| -> i32 {
|
||||
uumain(args)
|
||||
};
|
||||
|
||||
let _ = generate_and_run_uumain(&args, date_main, None);
|
||||
});
|
||||
|
||||
@@ -17,6 +17,13 @@ fn test_invalid_arg() {
|
||||
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_arguments() {
|
||||
new_ucmd!().arg("").fails_with_code(1);
|
||||
new_ucmd!().args(&["", ""]).fails_with_code(1);
|
||||
new_ucmd!().args(&["", "", ""]).fails_with_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_date_email() {
|
||||
for param in ["--rfc-email", "--rfc-e", "-R", "--rfc-2822", "--rfc-822"] {
|
||||
|
||||
Reference in New Issue
Block a user