mirror of
https://github.com/uutils/coreutils.git
synced 2025-07-07 21:45:01 +00:00
Merge pull request #7717 from drinkcat/fuzz-minor-fixes
Fuzzing: minor fixes
This commit is contained in:
commit
2103911d1a
13 changed files with 23 additions and 17 deletions
2
.github/workflows/fuzzing.yml
vendored
2
.github/workflows/fuzzing.yml
vendored
|
@ -84,7 +84,7 @@ jobs:
|
|||
shell: bash
|
||||
continue-on-error: ${{ !matrix.test-target.name.should_pass }}
|
||||
run: |
|
||||
cargo +nightly fuzz run ${{ matrix.test-target.name }} -- -max_total_time=${{ env.RUN_FOR }} -detect_leaks=0
|
||||
cargo +nightly fuzz run ${{ matrix.test-target.name }} -- -max_total_time=${{ env.RUN_FOR }} -timeout=${{ env.RUN_FOR }} -detect_leaks=0
|
||||
- name: Save Corpus Cache
|
||||
uses: actions/cache/save@v4
|
||||
with:
|
||||
|
|
|
@ -10,9 +10,10 @@ use std::ffi::OsString;
|
|||
use uu_cksum::uumain;
|
||||
mod fuzz_common;
|
||||
use crate::fuzz_common::{
|
||||
compare_result, generate_and_run_uumain, generate_random_file, generate_random_string,
|
||||
CommandResult, compare_result, generate_and_run_uumain, generate_random_file,
|
||||
generate_random_string,
|
||||
pretty_print::{print_or_empty, print_test_begin},
|
||||
replace_fuzz_binary_name, run_gnu_cmd, CommandResult,
|
||||
replace_fuzz_binary_name, run_gnu_cmd,
|
||||
};
|
||||
use rand::Rng;
|
||||
use std::env::temp_dir;
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
|
||||
use console::Style;
|
||||
use libc::STDIN_FILENO;
|
||||
use libc::{close, dup, dup2, pipe, STDERR_FILENO, STDOUT_FILENO};
|
||||
use libc::{STDERR_FILENO, STDOUT_FILENO, close, dup, dup2, pipe};
|
||||
use pretty_print::{
|
||||
print_diff, print_end_with_status, print_or_empty, print_section, print_with_style,
|
||||
};
|
||||
use rand::prelude::IndexedRandom;
|
||||
use rand::Rng;
|
||||
use rand::prelude::IndexedRandom;
|
||||
use std::env::temp_dir;
|
||||
use std::ffi::OsString;
|
||||
use std::fs::File;
|
||||
|
@ -18,7 +18,7 @@ use std::io::{Seek, SeekFrom, Write};
|
|||
use std::os::fd::{AsRawFd, RawFd};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::sync::{atomic::AtomicBool, Once};
|
||||
use std::sync::{Once, atomic::AtomicBool};
|
||||
use std::{io, thread};
|
||||
|
||||
pub mod pretty_print;
|
||||
|
@ -132,6 +132,8 @@ where
|
|||
let (uumain_exit_status, captured_stdout, captured_stderr) = thread::scope(|s| {
|
||||
let out = s.spawn(|| read_from_fd(pipe_stdout_fds[0]));
|
||||
let err = s.spawn(|| read_from_fd(pipe_stderr_fds[0]));
|
||||
#[allow(clippy::unnecessary_to_owned)]
|
||||
// TODO: clippy wants us to use args.iter().cloned() ?
|
||||
let status = uumain_function(args.to_owned().into_iter());
|
||||
// Reset the exit code global variable in case we run another test after this one
|
||||
// See https://github.com/uutils/coreutils/issues/5777
|
||||
|
@ -406,6 +408,7 @@ pub fn generate_random_string(max_length: usize) -> String {
|
|||
result
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn generate_random_file() -> Result<String, std::io::Error> {
|
||||
let mut rng = rand::rng();
|
||||
let file_name: String = (0..10)
|
||||
|
@ -426,6 +429,7 @@ pub fn generate_random_file() -> Result<String, std::io::Error> {
|
|||
Ok(file_path.to_str().unwrap().to_string())
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn replace_fuzz_binary_name(cmd: &str, result: &mut CommandResult) {
|
||||
let fuzz_bin_name = format!("fuzz/target/x86_64-unknown-linux-gnu/release/fuzz_{cmd}");
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
use std::fmt;
|
||||
|
||||
use console::{style, Style};
|
||||
use console::{Style, style};
|
||||
use similar::TextDiff;
|
||||
|
||||
pub fn print_section<S: fmt::Display>(s: S) {
|
||||
|
@ -16,6 +16,7 @@ pub fn print_subsection<S: fmt::Display>(s: S) {
|
|||
println!("{}", style(format!("--- {s}")).bright());
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn print_test_begin<S: fmt::Display>(msg: S) {
|
||||
println!(
|
||||
"{} {} {}",
|
||||
|
@ -49,7 +50,7 @@ pub fn print_with_style<S: fmt::Display>(msg: S, style: Style) {
|
|||
println!("{}", style.apply_to(msg));
|
||||
}
|
||||
|
||||
pub fn print_diff<'a, 'b>(got: &'a str, expected: &'b str) {
|
||||
pub fn print_diff(got: &str, expected: &str) {
|
||||
let diff = TextDiff::from_lines(got, expected);
|
||||
|
||||
print_subsection("START diff");
|
||||
|
|
|
@ -13,7 +13,7 @@ use std::ffi::OsString;
|
|||
|
||||
mod fuzz_common;
|
||||
use crate::fuzz_common::{
|
||||
compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd, CommandResult,
|
||||
CommandResult, compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd,
|
||||
};
|
||||
static CMD_PATH: &str = "cut";
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
use libfuzzer_sys::fuzz_target;
|
||||
use uu_echo::uumain;
|
||||
|
||||
use rand::prelude::IndexedRandom;
|
||||
use rand::Rng;
|
||||
use rand::prelude::IndexedRandom;
|
||||
use std::ffi::OsString;
|
||||
|
||||
mod fuzz_common;
|
||||
|
|
|
@ -12,7 +12,7 @@ use std::ffi::OsString;
|
|||
|
||||
mod fuzz_common;
|
||||
use crate::fuzz_common::{
|
||||
compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd, CommandResult,
|
||||
CommandResult, compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd,
|
||||
};
|
||||
use rand::Rng;
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
use libfuzzer_sys::fuzz_target;
|
||||
use uu_expr::uumain;
|
||||
|
||||
use rand::prelude::IndexedRandom;
|
||||
use rand::Rng;
|
||||
use rand::prelude::IndexedRandom;
|
||||
use std::{env, ffi::OsString};
|
||||
|
||||
mod fuzz_common;
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
use libfuzzer_sys::fuzz_target;
|
||||
use uu_printf::uumain;
|
||||
|
||||
use rand::seq::IndexedRandom;
|
||||
use rand::Rng;
|
||||
use rand::seq::IndexedRandom;
|
||||
use std::env;
|
||||
use std::ffi::OsString;
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use std::ffi::OsString;
|
|||
|
||||
mod fuzz_common;
|
||||
use crate::fuzz_common::{
|
||||
compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd, CommandResult,
|
||||
CommandResult, compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd,
|
||||
};
|
||||
static CMD_PATH: &str = "split";
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
use libfuzzer_sys::fuzz_target;
|
||||
use uu_test::uumain;
|
||||
|
||||
use rand::prelude::IndexedRandom;
|
||||
use rand::Rng;
|
||||
use rand::prelude::IndexedRandom;
|
||||
use std::ffi::OsString;
|
||||
|
||||
mod fuzz_common;
|
||||
|
|
|
@ -12,7 +12,7 @@ use rand::Rng;
|
|||
|
||||
mod fuzz_common;
|
||||
use crate::fuzz_common::{
|
||||
compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd, CommandResult,
|
||||
CommandResult, compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd,
|
||||
};
|
||||
static CMD_PATH: &str = "tr";
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use std::ffi::OsString;
|
|||
|
||||
mod fuzz_common;
|
||||
use crate::fuzz_common::{
|
||||
compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd, CommandResult,
|
||||
CommandResult, compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd,
|
||||
};
|
||||
static CMD_PATH: &str = "wc";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue