Skip to content
Open
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ feat_common_core = [
"numfmt",
"od",
"paste",
"pathchk",
"pr",
"printenv",
"printf",
Expand Down Expand Up @@ -198,6 +199,7 @@ feat_wasm = [
"numfmt",
"od",
"paste",
"pathchk",
"pr",
"printenv",
"printf",
Expand Down Expand Up @@ -287,7 +289,6 @@ feat_require_unix_core = [
"mknod",
"nice",
"nohup",
"pathchk",
"stat",
"stty",
"timeout",
Expand Down Expand Up @@ -316,7 +317,6 @@ feat_os_unix_fuchsia = [
"mkfifo",
"mknod",
"nice",
"pathchk",
"tty",
"uname",
"unlink",
Expand Down
22 changes: 18 additions & 4 deletions src/uu/pathchk/src/pathchk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ mod options {
const POSIX_PATH_MAX: usize = 256;
const POSIX_NAME_MAX: usize = 14;

#[cfg(all(unix, not(target_os = "redox")))]
const PATH_MAX: usize = libc::PATH_MAX as usize;
#[cfg(all(unix, not(target_os = "redox")))]
const FILENAME_MAX: usize = libc::FILENAME_MAX as usize;
#[cfg(target_os = "redox")]
const PATH_MAX: usize = 4096;
#[cfg(target_os = "redox")]
const FILENAME_MAX: usize = 255;
// for Windows. But don't deny wasm
#[cfg(not(unix))]
const PATH_MAX: usize = 260;
#[cfg(not(unix))]
const FILENAME_MAX: usize = 255;

#[uucore::main(no_signals)]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
Expand Down Expand Up @@ -193,11 +207,11 @@ fn check_default(path: &[String]) -> bool {
let joined_path = path.join("/");
let total_len = joined_path.len();
// path length
if total_len > libc::PATH_MAX as usize {
if total_len > PATH_MAX {
writeln!(
std::io::stderr(),
"{}",
translate!("pathchk-error-path-length-exceeded", "limit" => libc::PATH_MAX, "length" => total_len, "path" => joined_path.quote())
translate!("pathchk-error-path-length-exceeded", "limit" => PATH_MAX, "length" => total_len, "path" => joined_path.quote())
);
return false;
}
Expand All @@ -219,11 +233,11 @@ fn check_default(path: &[String]) -> bool {
// components: length
for p in path {
let component_len = p.len();
if component_len > libc::FILENAME_MAX as usize {
if component_len > FILENAME_MAX {
writeln!(
std::io::stderr(),
"{}",
translate!("pathchk-error-name-length-exceeded", "limit" => libc::FILENAME_MAX, "length" => component_len, "component" => p.quote())
translate!("pathchk-error-name-length-exceeded", "limit" => FILENAME_MAX, "length" => component_len, "component" => p.quote())
);
return false;
}
Expand Down
7 changes: 7 additions & 0 deletions tests/by-util/test_pathchk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
// file that was distributed with this source code.
#[cfg(target_os = "linux")]
use std::os::unix::ffi::OsStringExt;
#[cfg(unix)]
use uutests::new_ucmd;

#[test]
#[cfg(unix)]
fn test_no_args() {
new_ucmd!()
.fails()
Expand All @@ -15,11 +17,13 @@ fn test_no_args() {
}

#[test]
#[cfg(unix)]
fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
}

#[test]
#[cfg(unix)]
fn test_default_mode() {
// accept some reasonable default
new_ucmd!().args(&["dir/file"]).succeeds().no_stdout();
Expand Down Expand Up @@ -55,6 +59,7 @@ fn test_default_mode() {
}

#[test]
#[cfg(unix)]
fn test_posix_mode() {
// accept some reasonable default
new_ucmd!().args(&["-p", "dir/file"]).succeeds().no_stdout();
Expand All @@ -79,6 +84,7 @@ fn test_posix_mode() {
}

#[test]
#[cfg(unix)]
fn test_posix_special() {
// accept some reasonable default
new_ucmd!().args(&["-P", "dir/file"]).succeeds().no_stdout();
Expand Down Expand Up @@ -118,6 +124,7 @@ fn test_posix_special() {
}

#[test]
#[cfg(unix)]
fn test_posix_all() {
// accept some reasonable default
new_ucmd!()
Expand Down
Loading