Skip to content

Commit

Permalink
fchmodat/fstatat: fix regression with empty pathname
Browse files Browse the repository at this point in the history
In 4b82229 (Cygwin: fix errno values set by readlinkat, 2023-04-18)
the code of `readlinkat()` was adjusted to align the `errno` with Linux'
behavior.

To accommodate for that, the `gen_full_path_at()` function was modified,
and the caller was adjusted to expect either `ENOENT` or `ENOTDIR` in
the case of an empty `pathname`, not just `ENOENT`.

However, `readlinkat()` is not the only caller of that helper function.

And while most other callers simply propagate the `errno` produced by
`gen_full_path_at()`, two other callers also want to special-case empty
`pathnames` much like `readlinkat()`: `fchmodat()` and `fstatat()`.

Therefore, these two callers need to be changed to expect `ENOTDIR` in
case of an empty `pathname`, too.

I noticed this issue when one of my workflows failed consistently
while trying to untar an archive containing a symbolic link and
claiming this:

    Cannot change mode to rwxr-xr-x: Not a directory

With this here fix, things start working as expected again.

Fixes: 4b82229 (Cygwin: fix errno values set by readlinkat, 2023-04-18)
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Jul 4, 2023
1 parent 4c7d0df commit 072b5c5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions winsup/cygwin/syscalls.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4580,7 +4580,7 @@ fchownat (int dirfd, const char *pathname, uid_t uid, gid_t gid, int flags)
int res = gen_full_path_at (path, dirfd, pathname);
if (res)
{
if (!(errno == ENOENT && (flags & AT_EMPTY_PATH)))
if (!((errno == ENOENT || errno == ENOTDIR) && (flags & AT_EMPTY_PATH)))
__leave;
/* pathname is an empty string. Operate on dirfd. */
if (dirfd == AT_FDCWD)
Expand Down Expand Up @@ -4625,7 +4625,7 @@ fstatat (int dirfd, const char *__restrict pathname, struct stat *__restrict st,
int res = gen_full_path_at (path, dirfd, pathname);
if (res)
{
if (!(errno == ENOENT && (flags & AT_EMPTY_PATH)))
if (!((errno == ENOENT || errno == ENOTDIR) && (flags & AT_EMPTY_PATH)))
__leave;
/* pathname is an empty string. Operate on dirfd. */
if (dirfd == AT_FDCWD)
Expand Down

0 comments on commit 072b5c5

Please sign in to comment.