From f850ccd5b7df75c58aadbc086f9beda32e3809be Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Sat, 24 Jan 2026 16:04:25 +0000 Subject: [PATCH] fuzz: add cargo clippy check for fuzz directory --- .github/workflows/code-quality.yml | 6 ++++++ fuzz/.cargo/config.toml | 2 ++ fuzz/fuzz_targets/fuzz_non_utf8_paths.rs | 6 +++--- fuzz/fuzz_targets/fuzz_test.rs | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 fuzz/.cargo/config.toml diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index dcd81133ce4..b3c0a385a44 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -147,6 +147,12 @@ jobs: CARGO_UTILITY_LIST_OPTIONS="$(for u in ${UTILITY_LIST}; do echo -n "-puu_${u} "; done;)" S=$(cargo clippy --all-targets $extra --tests --benches -pcoreutils ${CARGO_UTILITY_LIST_OPTIONS} -- -D warnings 2>&1) && printf "%s\n" "$S" || { printf "%s\n" "$S" ; printf "%s" "$S" | sed -E -n -e '/^error:/{' -e "N; s/^error:[[:space:]]+(.*)\\n[[:space:]]+-->[[:space:]]+(.*):([0-9]+):([0-9]+).*$/::${fault_type} file=\2,line=\3,col=\4::${fault_prefix}: \`cargo clippy\`: \1 (file:'\2', line:\3)/p;" -e '}' ; fault=true ; } if [ -n "${{ steps.vars.outputs.FAIL_ON_FAULT }}" ] && [ -n "$fault" ]; then exit 1 ; fi + - name: "cargo clippy on fuzz dir" + if: runner.os != 'Windows' + shell: bash + run: | + cd fuzz + cargo clippy --workspace --all-targets --all-features -- -D warnings style_spellcheck: name: Style/spelling diff --git a/fuzz/.cargo/config.toml b/fuzz/.cargo/config.toml new file mode 100644 index 00000000000..5d1a2a27fca --- /dev/null +++ b/fuzz/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +rustflags = ["--cfg", "fuzzing"] diff --git a/fuzz/fuzz_targets/fuzz_non_utf8_paths.rs b/fuzz/fuzz_targets/fuzz_non_utf8_paths.rs index ac7480f3230..82e5374844b 100644 --- a/fuzz/fuzz_targets/fuzz_non_utf8_paths.rs +++ b/fuzz/fuzz_targets/fuzz_non_utf8_paths.rs @@ -14,7 +14,7 @@ use std::env::temp_dir; use std::ffi::{OsStr, OsString}; use std::fs; use std::os::unix::ffi::{OsStrExt, OsStringExt}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use uufuzz::{CommandResult, run_gnu_cmd}; // Programs that typically take file/path arguments and should be tested @@ -148,7 +148,7 @@ fn setup_test_files() -> Result<(PathBuf, Vec), std::io::Error> { // Try to create the file - this may fail on some filesystems if let Ok(mut file) = fs::File::create(&file_path) { use std::io::Write; - let _ = write!(file, "test content for file {}\n", i); + let _ = writeln!(file, "test content for file {}", i); test_files.push(file_path); } } @@ -156,7 +156,7 @@ fn setup_test_files() -> Result<(PathBuf, Vec), std::io::Error> { Ok((temp_root, test_files)) } -fn test_program_with_non_utf8_path(program: &str, path: &PathBuf) -> CommandResult { +fn test_program_with_non_utf8_path(program: &str, path: &Path) -> CommandResult { let path_os = path.as_os_str(); // Use the locally built uutils binary instead of system PATH diff --git a/fuzz/fuzz_targets/fuzz_test.rs b/fuzz/fuzz_targets/fuzz_test.rs index 894a1dcd56b..176ab9aba8f 100644 --- a/fuzz/fuzz_targets/fuzz_test.rs +++ b/fuzz/fuzz_targets/fuzz_test.rs @@ -135,9 +135,9 @@ fn generate_test_arg() -> String { if test_arg.arg_type == ArgType::INTEGER { arg.push_str(&format!( "{} {} {}", - rng.random_range(-100..=100).to_string(), + rng.random_range(-100..=100), test_arg.arg, - rng.random_range(-100..=100).to_string() + rng.random_range(-100..=100) )); } else if test_arg.arg_type == ArgType::STRINGSTRING { let random_str = generate_random_string(rng.random_range(1..=10));