mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
fuzz(cksum): fix fuzzer to use GNU's binary instead of the systems', remove false positives, improve logging
This commit is contained in:
parent
5d952afa3d
commit
6afa515859
1 changed files with 10 additions and 4 deletions
|
@ -11,7 +11,8 @@ use uu_cksum::uumain;
|
|||
mod fuzz_common;
|
||||
use crate::fuzz_common::{
|
||||
compare_result, generate_and_run_uumain, generate_random_file, generate_random_string,
|
||||
run_gnu_cmd, CommandResult,
|
||||
pretty_print::{print_or_empty, print_test_begin},
|
||||
replace_fuzz_binary_name, run_gnu_cmd, CommandResult,
|
||||
};
|
||||
use rand::Rng;
|
||||
use std::env::temp_dir;
|
||||
|
@ -129,13 +130,15 @@ fuzz_target!(|_data: &[u8]| {
|
|||
if let Ok(checksum_file_path) =
|
||||
generate_checksum_file(algo, &file_path, &selected_digest_opts)
|
||||
{
|
||||
print_test_begin(format!("cksum {:?}", args));
|
||||
|
||||
if let Ok(content) = fs::read_to_string(&checksum_file_path) {
|
||||
println!("File content: {checksum_file_path}={content}");
|
||||
println!("File content ({})", checksum_file_path);
|
||||
print_or_empty(&content);
|
||||
} else {
|
||||
eprintln!("Error reading the checksum file.");
|
||||
}
|
||||
println!("args: {:?}", args);
|
||||
let rust_result = generate_and_run_uumain(&args, uumain, None);
|
||||
let mut rust_result = generate_and_run_uumain(&args, uumain, None);
|
||||
|
||||
let gnu_result = match run_gnu_cmd(CMD_PATH, &args[1..], false, None) {
|
||||
Ok(result) => result,
|
||||
|
@ -151,6 +154,9 @@ fuzz_target!(|_data: &[u8]| {
|
|||
}
|
||||
};
|
||||
|
||||
// Lower the number of false positives caused by binary names
|
||||
replace_fuzz_binary_name("cksum", &mut rust_result);
|
||||
|
||||
compare_result(
|
||||
"cksum",
|
||||
&format!("{:?}", &args[1..]),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue