| Message ID | 20251219140600.212527-1-ghaderer@wyplay.com |
|---|---|
| State | New |
| Headers | show |
| Series | [pseudo] unix: realpath fails if the resolved path doesn't exist. | expand |
diff --git a/ports/unix/guts/realpath.c b/ports/unix/guts/realpath.c index 8d8118b..ee7d409 100644 --- a/ports/unix/guts/realpath.c +++ b/ports/unix/guts/realpath.c @@ -14,6 +14,14 @@ errno = ENAMETOOLONG; return NULL; } + + /* We must fail if the target path doesn't exist. */ + struct stat buf; + + if (base_lstat(rname, &buf) == -1) { + return NULL; + } + len = strlen(rname); char *ep = rname + len - 1; while (ep > rname && *ep == '/') {
The pseudo implementation of `realpath()' may return a path which doesn't exist. This is not POSIX compliant and causes troubles with uutils (coreutils in Rust). For example, the tail commands tries to determine the file path of its standard input file descriptor by calling `realpath("/dev/fd/0")'. When the input is a pipe, the GNU C library returns NULL but pseudo returns `/proc/<pid>/fd/pipe:[xxxxxx]'. As it got a path, the tail command tries to open it and fails. Upstream-Status: Pending --- ports/unix/guts/realpath.c | 8 ++++++++ 1 file changed, 8 insertions(+)