Skip to content
Draft
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
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -694,5 +694,7 @@ flat_map_option = "allow"
from_iter_instead_of_collect = "allow"
large_types_passed_by_value = "allow"

str_to_string = "warn"

[workspace.metadata.cargo-shear]
ignored = ["clap", "fluent", "libstdbuf"]
16 changes: 8 additions & 8 deletions fuzz/fuzz_targets/fuzz_cksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ fn generate_cksum_args() -> Vec<String> {
];

if rng.random_bool(0.3) {
args.push("-a".to_string());
args.push(digests[rng.random_range(0..digests.len())].to_string());
args.push("-a".to_owned());
args.push(digests[rng.random_range(0..digests.len())].to_owned());
}

if rng.random_bool(0.2) {
args.push(digest_opts[rng.random_range(0..digest_opts.len())].to_string());
args.push(digest_opts[rng.random_range(0..digest_opts.len())].to_owned());
}

if rng.random_bool(0.15) {
args.push("-l".to_string());
args.push("-l".to_owned());
args.push(rng.random_range(8..513).to_string());
}

Expand All @@ -58,7 +58,7 @@ fn generate_cksum_args() -> Vec<String> {
args.push(format!("file_{}", generate_random_string(5)));
}
} else {
args.push("-c".to_string());
args.push("-c".to_owned());
}

if rng.random_bool(0.25) {
Expand All @@ -68,8 +68,8 @@ fn generate_cksum_args() -> Vec<String> {
}

if args.is_empty() || !args.iter().any(|arg| arg.starts_with("file_")) {
args.push("-a".to_string());
args.push(digests[rng.random_range(0..digests.len())].to_string());
args.push("-a".to_owned());
args.push(digests[rng.random_range(0..digests.len())].to_owned());

if let Ok(file_path) = generate_random_file() {
args.push(file_path);
Expand Down Expand Up @@ -98,7 +98,7 @@ fn generate_checksum_file(
let mut checksum_file = File::create(&checksum_file_path)?;
checksum_file.write_all(&output.stdout)?;

Ok(checksum_file_path.to_str().unwrap().to_string())
Ok(checksum_file_path.to_str().unwrap().to_owned())
}

fn select_random_digest_opts<'a>(
Expand Down
12 changes: 6 additions & 6 deletions fuzz/fuzz_targets/fuzz_dirname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ fn generate_dirname_args() -> Vec<String> {
// 20% chance to include -z/--zero flag
if rng.random_bool(0.2) {
if rng.random_bool(0.5) {
args.push("-z".to_string());
args.push("-z".to_owned());
} else {
args.push("--zero".to_string());
args.push("--zero".to_owned());
}
}

Expand Down Expand Up @@ -77,11 +77,11 @@ fn generate_path() -> String {
}

// Root path
2 => "/".to_string(),
2 => "/".to_owned(),

// Absolute paths
3 => {
let mut path = "/".to_string();
let mut path = "/".to_owned();
let components = rng.random_range(1..=4);
for _ in 0..components {
path.push_str(&generate_random_string(rng.random_range(1..=8)));
Expand All @@ -97,7 +97,7 @@ fn generate_path() -> String {
// Paths ending with "/." (specific case from issue #8924)
4 => {
let base = if rng.random_bool(0.3) {
"/".to_string()
"/".to_owned()
} else {
format!("/{}", generate_random_string(rng.random_range(1..=10)))
};
Expand Down Expand Up @@ -132,7 +132,7 @@ fn generate_path() -> String {
}

// Empty string (edge case)
8 => "".to_string(),
8 => "".to_owned(),

// Issue #8924 specific cases: paths like "foo//."
9 => {
Expand Down
16 changes: 8 additions & 8 deletions fuzz/fuzz_targets/fuzz_non_utf8_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fn test_program_with_non_utf8_path(program: &str, path: &Path) -> CommandResult

// Use the locally built uutils binary instead of system PATH
let local_binary = std::env::var("CARGO_BIN_FILE_COREUTILS")
.unwrap_or_else(|_| "target/release/coreutils".to_string());
.unwrap_or_else(|_| "target/release/coreutils".to_owned());

// Build appropriate arguments for each program
let local_args = match program {
Expand All @@ -187,7 +187,7 @@ fn test_program_with_non_utf8_path(program: &str, path: &Path) -> CommandResult
],
"runcon" => {
let coreutils_binary = std::env::var("CARGO_BIN_FILE_COREUTILS")
.unwrap_or_else(|_| "target/release/coreutils".to_string());
.unwrap_or_else(|_| "target/release/coreutils".to_owned());
vec![
OsString::from(program),
OsString::from("system_u:object_r:admin_home_t:s0"),
Expand Down Expand Up @@ -271,7 +271,7 @@ fn test_program_with_non_utf8_path(program: &str, path: &Path) -> CommandResult
"tty" => vec![OsString::from(program)], // tty doesn't take file args, but test anyway
"env" => {
let coreutils_binary = std::env::var("CARGO_BIN_FILE_COREUTILS")
.unwrap_or_else(|_| "target/release/coreutils".to_string());
.unwrap_or_else(|_| "target/release/coreutils".to_owned());
vec![
OsString::from(program),
OsString::from(coreutils_binary),
Expand All @@ -281,7 +281,7 @@ fn test_program_with_non_utf8_path(program: &str, path: &Path) -> CommandResult
}
"nohup" => {
let coreutils_binary = std::env::var("CARGO_BIN_FILE_COREUTILS")
.unwrap_or_else(|_| "target/release/coreutils".to_string());
.unwrap_or_else(|_| "target/release/coreutils".to_owned());
vec![
OsString::from(program),
OsString::from(coreutils_binary),
Expand All @@ -291,7 +291,7 @@ fn test_program_with_non_utf8_path(program: &str, path: &Path) -> CommandResult
}
"nice" => {
let coreutils_binary = std::env::var("CARGO_BIN_FILE_COREUTILS")
.unwrap_or_else(|_| "target/release/coreutils".to_string());
.unwrap_or_else(|_| "target/release/coreutils".to_owned());
vec![
OsString::from(program),
OsString::from(coreutils_binary),
Expand All @@ -301,7 +301,7 @@ fn test_program_with_non_utf8_path(program: &str, path: &Path) -> CommandResult
}
"timeout" => {
let coreutils_binary = std::env::var("CARGO_BIN_FILE_COREUTILS")
.unwrap_or_else(|_| "target/release/coreutils".to_string());
.unwrap_or_else(|_| "target/release/coreutils".to_owned());
vec![
OsString::from(program),
OsString::from("1"),
Expand All @@ -312,7 +312,7 @@ fn test_program_with_non_utf8_path(program: &str, path: &Path) -> CommandResult
}
"stdbuf" => {
let coreutils_binary = std::env::var("CARGO_BIN_FILE_COREUTILS")
.unwrap_or_else(|_| "target/release/coreutils".to_string());
.unwrap_or_else(|_| "target/release/coreutils".to_owned());
vec![
OsString::from(program),
OsString::from("-o0"),
Expand Down Expand Up @@ -413,7 +413,7 @@ fuzz_target!(|_data: &[u8]| {
let non_utf8_dir = temp_root.join(non_utf8_dir_name);

let local_binary = std::env::var("CARGO_BIN_FILE_COREUTILS")
.unwrap_or_else(|_| "target/release/coreutils".to_string());
.unwrap_or_else(|_| "target/release/coreutils".to_owned());
let mkdir_args = vec![OsString::from("mkdir"), non_utf8_dir.as_os_str().to_owned()];

let mkdir_result = run_gnu_cmd(&local_binary, &mkdir_args, false, None);
Expand Down
34 changes: 17 additions & 17 deletions fuzz/fuzz_targets/fuzz_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,71 +47,71 @@ fn generate_random_path(rng: &mut dyn rand::RngCore) -> &'static str {
fn generate_test_args() -> Vec<TestArg> {
vec![
TestArg {
arg: "-z".to_string(),
arg: "-z".to_owned(),
arg_type: ArgType::STRING,
},
TestArg {
arg: "-n".to_string(),
arg: "-n".to_owned(),
arg_type: ArgType::STRING,
},
TestArg {
arg: "=".to_string(),
arg: "=".to_owned(),
arg_type: ArgType::STRINGSTRING,
},
TestArg {
arg: "!=".to_string(),
arg: "!=".to_owned(),
arg_type: ArgType::STRINGSTRING,
},
TestArg {
arg: ">".to_string(),
arg: ">".to_owned(),
arg_type: ArgType::STRINGSTRING,
},
TestArg {
arg: "<".to_string(),
arg: "<".to_owned(),
arg_type: ArgType::STRINGSTRING,
},
TestArg {
arg: "-eq".to_string(),
arg: "-eq".to_owned(),
arg_type: ArgType::INTEGERINTEGER,
},
TestArg {
arg: "-ne".to_string(),
arg: "-ne".to_owned(),
arg_type: ArgType::INTEGERINTEGER,
},
TestArg {
arg: "-gt".to_string(),
arg: "-gt".to_owned(),
arg_type: ArgType::INTEGERINTEGER,
},
TestArg {
arg: "-ge".to_string(),
arg: "-ge".to_owned(),
arg_type: ArgType::INTEGERINTEGER,
},
TestArg {
arg: "-lt".to_string(),
arg: "-lt".to_owned(),
arg_type: ArgType::INTEGERINTEGER,
},
TestArg {
arg: "-le".to_string(),
arg: "-le".to_owned(),
arg_type: ArgType::INTEGERINTEGER,
},
TestArg {
arg: "-f".to_string(),
arg: "-f".to_owned(),
arg_type: ArgType::FILE,
},
TestArg {
arg: "-d".to_string(),
arg: "-d".to_owned(),
arg_type: ArgType::FILE,
},
TestArg {
arg: "-e".to_string(),
arg: "-e".to_owned(),
arg_type: ArgType::FILE,
},
TestArg {
arg: "-ef".to_string(),
arg: "-ef".to_owned(),
arg_type: ArgType::FILEFILE,
},
TestArg {
arg: "-nt".to_string(),
arg: "-nt".to_owned(),
arg_type: ArgType::FILEFILE,
},
]
Expand Down
2 changes: 1 addition & 1 deletion fuzz/uufuzz/examples/simple_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn main() {

// Simulate our own echo implementation result
let our_result = CommandResult {
stdout: "hello world\n".to_string(),
stdout: "hello world\n".to_owned(),
stderr: String::new(),
exit_code: 0,
};
Expand Down
38 changes: 19 additions & 19 deletions fuzz/uufuzz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ where
let original_stderr_fd = unsafe { dup(STDERR_FILENO) };
if original_stdout_fd == -1 || original_stderr_fd == -1 {
return CommandResult {
stdout: "".to_string(),
stderr: "Failed to duplicate STDOUT_FILENO or STDERR_FILENO".to_string(),
stdout: "".to_owned(),
stderr: "Failed to duplicate STDOUT_FILENO or STDERR_FILENO".to_owned(),
exit_code: -1,
};
}
Expand All @@ -87,8 +87,8 @@ where
|| unsafe { pipe(pipe_stderr_fds.as_mut_ptr()) } == -1
{
return CommandResult {
stdout: "".to_string(),
stderr: "Failed to create pipes".to_string(),
stdout: "".to_owned(),
stderr: "Failed to create pipes".to_owned(),
exit_code: -1,
};
}
Expand All @@ -104,8 +104,8 @@ where
close(pipe_stderr_fds[1]);
}
return CommandResult {
stdout: "".to_string(),
stderr: "Failed to redirect STDOUT_FILENO or STDERR_FILENO".to_string(),
stdout: "".to_owned(),
stderr: "Failed to redirect STDOUT_FILENO or STDERR_FILENO".to_owned(),
exit_code: -1,
};
}
Expand All @@ -120,8 +120,8 @@ where
let original_stdin_fd = unsafe { dup(STDIN_FILENO) };
if original_stdin_fd == -1 || unsafe { dup2(input_file.as_raw_fd(), STDIN_FILENO) } == -1 {
return CommandResult {
stdout: "".to_string(),
stderr: "Failed to set up stdin redirection".to_string(),
stdout: "".to_owned(),
stderr: "Failed to set up stdin redirection".to_owned(),
exit_code: -1,
};
}
Expand Down Expand Up @@ -155,8 +155,8 @@ where
|| unsafe { dup2(original_stderr_fd, STDERR_FILENO) } == -1
{
return CommandResult {
stdout: "".to_string(),
stderr: "Failed to restore the original STDOUT_FILENO or STDERR_FILENO".to_string(),
stdout: "".to_owned(),
stderr: "Failed to restore the original STDOUT_FILENO or STDERR_FILENO".to_owned(),
exit_code: -1,
};
}
Expand All @@ -169,8 +169,8 @@ where
if let Some(fd) = original_stdin_fd {
if unsafe { dup2(fd, STDIN_FILENO) } == -1 {
return CommandResult {
stdout: "".to_string(),
stderr: "Failed to restore the original STDIN".to_string(),
stdout: "".to_owned(),
stderr: "Failed to restore the original STDIN".to_owned(),
exit_code: -1,
};
}
Expand All @@ -184,7 +184,7 @@ where
.map(|x| x.1)
.unwrap_or("")
.trim()
.to_string(),
.to_owned(),
exit_code: uumain_exit_status,
}
}
Expand Down Expand Up @@ -285,7 +285,7 @@ pub fn run_gnu_cmd(
.map(|x| x.1)
.unwrap_or("")
.trim()
.to_string();
.to_owned();

if output.status.success() || !check_gnu {
Ok(CommandResult {
Expand Down Expand Up @@ -423,7 +423,7 @@ pub fn generate_random_file() -> Result<String, std::io::Error> {

file.write_all(content.as_bytes())?;

Ok(file_path.to_str().unwrap().to_string())
Ok(file_path.to_str().unwrap().to_owned())
}

#[allow(dead_code)]
Expand All @@ -442,8 +442,8 @@ mod tests {
#[test]
fn test_command_result_creation() {
let result = CommandResult {
stdout: "Hello, world!".to_string(),
stderr: "".to_string(),
stdout: "Hello, world!".to_owned(),
stderr: "".to_owned(),
exit_code: 0,
};

Expand All @@ -466,8 +466,8 @@ mod tests {
#[test]
fn test_replace_fuzz_binary_name() {
let mut result = CommandResult {
stdout: "fuzz/target/x86_64-unknown-linux-gnu/release/fuzz_echo: error".to_string(),
stderr: "fuzz/target/x86_64-unknown-linux-gnu/release/fuzz_echo failed".to_string(),
stdout: "fuzz/target/x86_64-unknown-linux-gnu/release/fuzz_echo: error".to_owned(),
stderr: "fuzz/target/x86_64-unknown-linux-gnu/release/fuzz_echo failed".to_owned(),
exit_code: 1,
};

Expand Down
Loading
Loading