Skip to content

Create an uufuzz crate for common functions and use it #7954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 21, 2025
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
1 change: 1 addition & 0 deletions .vscode/cspell.dictionaries/workspace.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ utmpx
uucore
uucore_procs
uudoc
uufuzz
uumain
uutil
uutests
Expand Down
17 changes: 13 additions & 4 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
[package]
name = "uucore-fuzz"
version = "0.0.0"
description = "uutils ~ 'core' uutils fuzzers"
repository = "https://github.com/uutils/coreutils/tree/main/fuzz/"
edition.workspace = true
publish = false

[workspace.package]
edition = "2024"
license = "MIT"

[package.metadata]
cargo-fuzz = true

[dependencies]
console = "0.15.0"
libfuzzer-sys = "0.4.7"
libc = "0.2.153"
tempfile = "3.15.0"
rand = { version = "0.9.0", features = ["small_rng"] }
similar = "2.5.0"

uufuzz = { path = "uufuzz/" }
uucore = { path = "../src/uucore/", features = ["parser"] }
uu_date = { path = "../src/uu/date/" }
uu_test = { path = "../src/uu/test/" }
Expand Down
13 changes: 6 additions & 7 deletions fuzz/fuzz_targets/fuzz_cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@

#![no_main]
use libfuzzer_sys::fuzz_target;
use rand::Rng;
use std::env::temp_dir;
use std::ffi::OsString;
use std::fs::{self, File};
use std::io::Write;
use std::process::Command;
use uu_cksum::uumain;
mod fuzz_common;
use crate::fuzz_common::{
use uufuzz::{
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,
};
use rand::Rng;
use std::env::temp_dir;
use std::fs::{self, File};
use std::io::Write;
use std::process::Command;

static CMD_PATH: &str = "cksum";

Expand Down
3 changes: 1 addition & 2 deletions fuzz/fuzz_targets/fuzz_cut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use uu_cut::uumain;
use rand::Rng;
use std::ffi::OsString;

mod fuzz_common;
use crate::fuzz_common::{
use uufuzz::{
CommandResult, compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd,
};
static CMD_PATH: &str = "cut";
Expand Down
7 changes: 2 additions & 5 deletions fuzz/fuzz_targets/fuzz_echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ use rand::Rng;
use rand::prelude::IndexedRandom;
use std::ffi::OsString;

mod fuzz_common;
use crate::fuzz_common::CommandResult;
use crate::fuzz_common::{
compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd,
};
use uufuzz::CommandResult;
use uufuzz::{compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd};

static CMD_PATH: &str = "echo";

Expand Down
5 changes: 2 additions & 3 deletions fuzz/fuzz_targets/fuzz_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ use uu_env::uumain;

use std::ffi::OsString;

mod fuzz_common;
use crate::fuzz_common::{
use rand::Rng;
use uufuzz::{
CommandResult, compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd,
};
use rand::Rng;

static CMD_PATH: &str = "env";

Expand Down
7 changes: 2 additions & 5 deletions fuzz/fuzz_targets/fuzz_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ use rand::Rng;
use rand::prelude::IndexedRandom;
use std::{env, ffi::OsString};

mod fuzz_common;
use crate::fuzz_common::CommandResult;
use crate::fuzz_common::{
compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd,
};
use uufuzz::CommandResult;
use uufuzz::{compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd};
static CMD_PATH: &str = "expr";

fn generate_expr(max_depth: u32) -> String {
Expand Down
7 changes: 2 additions & 5 deletions fuzz/fuzz_targets/fuzz_printf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ use rand::seq::IndexedRandom;
use std::env;
use std::ffi::OsString;

mod fuzz_common;
use crate::fuzz_common::CommandResult;
use crate::fuzz_common::{
compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd,
};
use uufuzz::CommandResult;
use uufuzz::{compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd};

static CMD_PATH: &str = "printf";

Expand Down
7 changes: 2 additions & 5 deletions fuzz/fuzz_targets/fuzz_seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ use uu_seq::uumain;
use rand::Rng;
use std::ffi::OsString;

mod fuzz_common;
use crate::fuzz_common::CommandResult;
use crate::fuzz_common::{
compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd,
};
use uufuzz::CommandResult;
use uufuzz::{compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd};
static CMD_PATH: &str = "seq";

fn generate_seq() -> String {
Expand Down
7 changes: 2 additions & 5 deletions fuzz/fuzz_targets/fuzz_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ use rand::Rng;
use std::env;
use std::ffi::OsString;

mod fuzz_common;
use crate::fuzz_common::CommandResult;
use crate::fuzz_common::{
compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd,
};
use uufuzz::CommandResult;
use uufuzz::{compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd};
static CMD_PATH: &str = "sort";

fn generate_sort_args() -> String {
Expand Down
3 changes: 1 addition & 2 deletions fuzz/fuzz_targets/fuzz_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use uu_split::uumain;
use rand::Rng;
use std::ffi::OsString;

mod fuzz_common;
use crate::fuzz_common::{
use uufuzz::{
CommandResult, compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd,
};
static CMD_PATH: &str = "split";
Expand Down
12 changes: 3 additions & 9 deletions fuzz/fuzz_targets/fuzz_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ use rand::Rng;
use rand::prelude::IndexedRandom;
use std::ffi::OsString;

mod fuzz_common;
use crate::fuzz_common::CommandResult;
use crate::fuzz_common::{
compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd,
};
use uufuzz::CommandResult;
use uufuzz::{compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd};

#[allow(clippy::upper_case_acronyms)]
#[derive(PartialEq, Debug, Clone)]
Expand Down Expand Up @@ -146,10 +143,7 @@ fn generate_test_arg() -> String {
let random_str = generate_random_string(rng.random_range(1..=10));
let random_str2 = generate_random_string(rng.random_range(1..=10));

arg.push_str(&format!(
"{random_str} {} {random_str2}",
test_arg.arg,
));
arg.push_str(&format!("{random_str} {} {random_str2}", test_arg.arg,));
} else if test_arg.arg_type == ArgType::STRING {
let random_str = generate_random_string(rng.random_range(1..=10));
arg.push_str(&format!("{} {random_str}", test_arg.arg));
Expand Down
3 changes: 1 addition & 2 deletions fuzz/fuzz_targets/fuzz_tr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use uu_tr::uumain;

use rand::Rng;

mod fuzz_common;
use crate::fuzz_common::{
use uufuzz::{
CommandResult, compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd,
};
static CMD_PATH: &str = "tr";
Expand Down
3 changes: 1 addition & 2 deletions fuzz/fuzz_targets/fuzz_wc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use uu_wc::uumain;
use rand::Rng;
use std::ffi::OsString;

mod fuzz_common;
use crate::fuzz_common::{
use uufuzz::{
CommandResult, compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd,
};
static CMD_PATH: &str = "wc";
Expand Down
17 changes: 17 additions & 0 deletions fuzz/uufuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "uufuzz"
authors = ["uutils developers"]
description = "uutils ~ 'core' uutils fuzzing library"
repository = "https://github.com/uutils/coreutils/tree/main/fuzz/uufuzz"
version = "0.0.30"
edition.workspace = true
license.workspace = true


[dependencies]
console = "0.15.0"
libc = "0.2.153"
rand = { version = "0.9.0", features = ["small_rng"] }
similar = "2.5.0"
uucore = { path = "../../src/uucore/", features = ["parser"] }
tempfile = "3.15.0"
File renamed without changes.
Loading