From 1ab8555a94ec128e7f8f9dd172c96e7d375ebce4 Mon Sep 17 00:00:00 2001 From: Zhuoxun Yang Date: Wed, 18 Oct 2023 22:50:43 +0800 Subject: [PATCH] pathchk: check empty path --- src/uu/pathchk/src/pathchk.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/uu/pathchk/src/pathchk.rs b/src/uu/pathchk/src/pathchk.rs index 3510a3327..81c352088 100644 --- a/src/uu/pathchk/src/pathchk.rs +++ b/src/uu/pathchk/src/pathchk.rs @@ -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();