Skip to content

Commit

Permalink
Merge branch 'main' into feature/terminal_simulation_for_windows
Browse files Browse the repository at this point in the history
# Conflicts:
#	Cargo.lock
  • Loading branch information
cre4ture committed Apr 6, 2024
2 parents b01f9f1 + 56e59da commit f206be2
Show file tree
Hide file tree
Showing 27 changed files with 452 additions and 81 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,6 @@ jobs:
PKG_BASENAME=${PROJECT_NAME}-${REF_TAG:-$REF_SHAS}-${{ matrix.job.target }}
PKG_NAME=${PKG_BASENAME}${PKG_suffix}
outputs PKG_suffix PKG_BASENAME PKG_NAME
# deployable tag? (ie, leading "vM" or "M"; M == version number)
unset DEPLOY ; if [[ $REF_TAG =~ ^[vV]?[0-9].* ]]; then DEPLOY='true' ; fi
outputs DEPLOY
# DPKG architecture?
unset DPKG_ARCH
case ${{ matrix.job.target }} in
Expand Down Expand Up @@ -749,7 +746,7 @@ jobs:
fi
- name: Publish
uses: softprops/action-gh-release@v2
if: steps.vars.outputs.DEPLOY
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_NAME }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
command: |
## `cargo clippy` lint testing
unset fault
CLIPPY_FLAGS="-W clippy::default_trait_access -W clippy::manual_string_new -W clippy::cognitive_complexity -W clippy::implicit_clone -W clippy::range-plus-one -W clippy::redundant-clone"
CLIPPY_FLAGS="-W clippy::default_trait_access -W clippy::manual_string_new -W clippy::cognitive_complexity -W clippy::implicit_clone -W clippy::range-plus-one -W clippy::redundant-clone -W clippy::match_bool"
fault_type="${{ steps.vars.outputs.FAULT_TYPE }}"
fault_prefix=$(echo "$fault_type" | tr '[:lower:]' '[:upper:]')
# * convert any warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message>
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/freebsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.4
- name: Prepare, build and test
uses: vmactions/freebsd-vm@v1.0.6
uses: vmactions/freebsd-vm@v1.0.7
with:
usesh: true
sync: rsync
Expand Down Expand Up @@ -131,7 +131,7 @@ jobs:
- name: Run sccache-cache
uses: mozilla-actions/sccache-action@v0.0.4
- name: Prepare, build and test
uses: vmactions/freebsd-vm@v1.0.6
uses: vmactions/freebsd-vm@v1.0.7
with:
usesh: true
sync: rsync
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/fuzzing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ jobs:
- { name: fuzz_wc, should_pass: false }
- { name: fuzz_cut, should_pass: false }
- { name: fuzz_split, should_pass: false }
- { name: fuzz_tr, should_pass: false }
- { name: fuzz_env, should_pass: false }
- { name: fuzz_parse_glob, should_pass: true }
- { name: fuzz_parse_size, should_pass: true }
- { name: fuzz_parse_time, should_pass: true }
Expand Down
35 changes: 24 additions & 11 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ fundu = "2.0.0"
gcd = "2.3"
glob = "0.3.1"
half = "2.4"
hostname = "0.3"
hostname = "0.4"
indicatif = "0.17"
itertools = "0.12.1"
libc = "0.2.153"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ that scripts can be easily transferred between platforms.
## Documentation
uutils has both user and developer documentation available:

- [User Manual](https://uutils.github.io/coreutils/book/)
- [User Manual](https://uutils.github.io/coreutils/docs/)
- [Developer Documentation](https://docs.rs/crate/coreutils/)

Both can also be generated locally, the instructions for that can be found in
Expand Down Expand Up @@ -302,7 +302,7 @@ make PREFIX=/my/path uninstall

Below is the evolution of how many GNU tests uutils passes. A more detailed
breakdown of the GNU test results of the main branch can be found
[in the user manual](https://uutils.github.io/coreutils/book/test_coverage.html).
[in the user manual](https://uutils.github.io/coreutils/docs/test_coverage.html).

See <https://github.com/orgs/uutils/projects/1> for the main meta bugs
(many are missing).
Expand Down
14 changes: 14 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ uu_sort = { path = "../src/uu/sort/" }
uu_wc = { path = "../src/uu/wc/" }
uu_cut = { path = "../src/uu/cut/" }
uu_split = { path = "../src/uu/split/" }
uu_tr = { path = "../src/uu/tr/" }
uu_env = { path = "../src/uu/env/" }

# Prevent this from interfering with workspaces
[workspace]
Expand Down Expand Up @@ -107,3 +109,15 @@ name = "fuzz_parse_time"
path = "fuzz_targets/fuzz_parse_time.rs"
test = false
doc = false

[[bin]]
name = "fuzz_tr"
path = "fuzz_targets/fuzz_tr.rs"
test = false
doc = false

[[bin]]
name = "fuzz_env"
path = "fuzz_targets/fuzz_env.rs"
test = false
doc = false
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/fuzz_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ pub fn generate_random_string(max_length: usize) -> String {
let invalid_utf8 = [0xC3, 0x28]; // Invalid UTF-8 sequence
let mut result = String::new();

for _ in 0..rng.gen_range(1..=max_length) {
for _ in 0..rng.gen_range(0..=max_length) {
if rng.gen_bool(0.9) {
let ch = valid_utf8.choose(&mut rng).unwrap();
result.push(*ch);
Expand Down
1 change: 1 addition & 0 deletions fuzz/fuzz_targets/fuzz_echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fn generate_echo() -> String {
// Randomly decide whether to include options
let include_n = rng.gen_bool(0.1); // 10% chance
let include_e = rng.gen_bool(0.1); // 10% chance
#[allow(non_snake_case)]
let include_E = rng.gen_bool(0.1); // 10% chance

if include_n {
Expand Down
97 changes: 97 additions & 0 deletions fuzz/fuzz_targets/fuzz_env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// This file is part of the uutils coreutils package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
// spell-checker:ignore chdir

#![no_main]
use libfuzzer_sys::fuzz_target;
use uu_env::uumain;

use std::ffi::OsString;

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

static CMD_PATH: &str = "env";

fn generate_env_args() -> Vec<String> {
let mut rng = rand::thread_rng();
let mut args = Vec::new();

let opts = ["-i", "-0", "-v", "-vv"];
for opt in &opts {
if rng.gen_bool(0.2) {
args.push(opt.to_string());
}
}

if rng.gen_bool(0.3) {
args.push(format!(
"-u={}",
generate_random_string(rng.gen_range(3..10))
));
}

if rng.gen_bool(0.2) {
args.push(format!("--chdir={}", "/tmp")); // Simplified example
}

/*
Options not implemented for now
if rng.gen_bool(0.15) {
let sig_opts = ["--block-signal"];//, /*"--default-signal",*/ "--ignore-signal"];
let chosen_sig_opt = sig_opts[rng.gen_range(0..sig_opts.len())];
args.push(chosen_sig_opt.to_string());
// Simplify by assuming SIGPIPE for demonstration
if !chosen_sig_opt.ends_with("list-signal-handling") {
args.push(String::from("SIGPIPE"));
}
}*/

// Adding a few random NAME=VALUE pairs
for _ in 0..rng.gen_range(0..3) {
args.push(format!(
"{}={}",
generate_random_string(5),
generate_random_string(5)
));
}

args
}

fuzz_target!(|_data: &[u8]| {
let env_args = generate_env_args();
let mut args = vec![OsString::from("env")];
args.extend(env_args.iter().map(OsString::from));
let input_lines = generate_random_string(10);

let rust_result = generate_and_run_uumain(&args, uumain, Some(&input_lines));

let gnu_result = match run_gnu_cmd(CMD_PATH, &args[1..], false, None) {
Ok(result) => result,
Err(error_result) => {
eprintln!("Failed to run GNU command:");
eprintln!("Stderr: {}", error_result.stderr);
eprintln!("Exit Code: {}", error_result.exit_code);
CommandResult {
stdout: String::new(),
stderr: error_result.stderr,
exit_code: error_result.exit_code,
}
}
};

compare_result(
"env",
&format!("{:?}", &args[1..]),
None,
&rust_result,
&gnu_result,
false,
);
});
3 changes: 2 additions & 1 deletion fuzz/fuzz_targets/fuzz_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ static CMD_PATH: &str = "expr";
fn generate_expr(max_depth: u32) -> String {
let mut rng = rand::thread_rng();
let ops = [
"+", "-", "*", "/", "%", "<", ">", "=", "&", "|", "!=", "<=", ">=", ":", "index", "length", "substr",
"+", "-", "*", "/", "%", "<", ">", "=", "&", "|", "!=", "<=", ">=", ":", "index", "length",
"substr",
];

let mut expr = String::new();
Expand Down
1 change: 1 addition & 0 deletions fuzz/fuzz_targets/fuzz_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::fuzz_common::{
compare_result, generate_and_run_uumain, generate_random_string, run_gnu_cmd,
};

#[allow(clippy::upper_case_acronyms)]
#[derive(PartialEq, Debug, Clone)]
enum ArgType {
STRING,
Expand Down
73 changes: 73 additions & 0 deletions fuzz/fuzz_targets/fuzz_tr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// This file is part of the uutils coreutils package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

#![no_main]
use libfuzzer_sys::fuzz_target;
use std::ffi::OsString;
use uu_tr::uumain;

use rand::Rng;

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

fn generate_tr_args() -> Vec<String> {
let mut rng = rand::thread_rng();
let mut args = Vec::new();

// Translate, squeeze, and/or delete characters
let opts = ["-c", "-d", "-s", "-t"];
for opt in &opts {
if rng.gen_bool(0.25) {
args.push(opt.to_string());
}
}

// Generating STRING1 and optionally STRING2
let string1 = generate_random_string(rng.gen_range(1..=20));
args.push(string1);
if rng.gen_bool(0.7) {
// Higher chance to add STRING2 for translation
let string2 = generate_random_string(rng.gen_range(1..=20));
args.push(string2);
}

args
}

fuzz_target!(|_data: &[u8]| {
let tr_args = generate_tr_args();
let mut args = vec![OsString::from("tr")];
args.extend(tr_args.iter().map(OsString::from));

let input_chars = generate_random_string(100);

let rust_result = generate_and_run_uumain(&args, uumain, Some(&input_chars));
let gnu_result = match run_gnu_cmd(CMD_PATH, &args[1..], false, Some(&input_chars)) {
Ok(result) => result,
Err(error_result) => {
eprintln!("Failed to run GNU command:");
eprintln!("Stderr: {}", error_result.stderr);
eprintln!("Exit Code: {}", error_result.exit_code);
CommandResult {
stdout: String::new(),
stderr: error_result.stderr,
exit_code: error_result.exit_code,
}
}
};

compare_result(
"tr",
&format!("{:?}", &args[1..]),
Some(&input_chars),
&rust_result,
&gnu_result,
false,
);
});
Loading

0 comments on commit f206be2

Please sign in to comment.