forked from uutils/coreutils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/terminal_simulation_for_windows
# Conflicts: # Cargo.lock
- Loading branch information
Showing
27 changed files
with
452 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
}); |
Oops, something went wrong.