Skip to content
Merged
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
7 changes: 4 additions & 3 deletions src/uu/pathchk/src/pathchk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,12 @@ fn check_path(mode: &Mode, path: &[String]) -> bool {
fn check_basic(path: &[String]) -> bool {
let joined_path = path.join("/");
let total_len = joined_path.len();
// path length
if total_len > POSIX_PATH_MAX {
// _POSIX_PATH_MAX counts the terminating null byte, so the
// longest portable file name is one byte shorter
if total_len >= POSIX_PATH_MAX {
show_error!(
"{}",
translate!("pathchk-error-posix-path-length-exceeded", "limit" => POSIX_PATH_MAX, "length" => total_len, "path" => joined_path)
translate!("pathchk-error-posix-path-length-exceeded", "limit" => POSIX_PATH_MAX - 1, "length" => total_len, "path" => joined_path.quote())
);
return false;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/by-util/test_pathchk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ fn test_posix_mode() {
.fails()
.no_stdout();

// _POSIX_PATH_MAX (256) includes the terminating null byte, so 255 bytes
// is the longest portable file name
new_ucmd!()
.args(&["-p", &format!("{}a", "a/".repeat(127))])
.succeeds()
.no_output();
let path = format!("{}ab", "a/".repeat(127));
new_ucmd!()
.args(&["-p", &path])
.fails_with_code(1)
.stderr_only(format!(
"pathchk: limit 255 exceeded by length 256 of file name '{path}'\n"
));

// fail on long filename
new_ucmd!()
.args(&[
Expand Down
Loading