Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pathchk: check empty path by default #5423

Merged
merged 3 commits into from
Oct 19, 2023
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
11 changes: 11 additions & 0 deletions src/uu/pathchk/src/pathchk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ fn check_default(path: &[String]) -> bool {
);
return false;
}
if total_len == 0 {
// Check whether a file name component is in a directory that is not searchable,
// or has some other serious problem. POSIX does not allow "" as a file name,
// but some non-POSIX hosts do (as an alias for "."),
// so allow "" if `symlink_metadata` (corresponds to `lstat`) does.
if fs::symlink_metadata(&joined_path).is_err() {
writeln!(std::io::stderr(), "pathchk: '': No such file or directory",);
return false;
}
}

// components: length
for p in path {
let component_len = p.len();
Expand Down
12 changes: 10 additions & 2 deletions tests/by-util/test_pathchk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ fn test_default_mode() {
// accept non-portable chars
new_ucmd!().args(&["dir#/$file"]).succeeds().no_stdout();

// accept empty path
new_ucmd!().args(&[""]).succeeds().no_stdout();
// fail on empty path
new_ucmd!()
.args(&[""])
.fails()
.stderr_only("pathchk: '': No such file or directory\n");

new_ucmd!().args(&["", ""]).fails().stderr_only(
"pathchk: '': No such file or directory\n\
pathchk: '': No such file or directory\n",
);

// fail on long path
new_ucmd!()
Expand Down
Loading