Re: [PATCH 6/8] fchmodat: don’t mishandle AT_EMPTY_PATH

Bruno Haible via Gnulib discussion list <[email protected]>
Newsgroups gmane.comp.lib.gnulib.bugs
Organization GNU
Message-ID <3414063.oiGErgHkdL@nimes>
Paul Eggert wrote:
>  int
>  fchmodat (int dir, char const *file, mode_t mode, int flags)
>  {
> +  if (file && *file)
> +    flags &= ~AT_EMPTY_PATH;
> +  else if (! (flags & AT_EMPTY_PATH))
> +    {
> +      errno = ENOENT;
> +      return -1;
> +    }
> +  else if (! (flags & AT_SYMLINK_NOFOLLOW))
> +    return fchmod (dir, mode);

Shouldn't the last line read

       return fchmod (dir == AT_FDCWD ? "." : dir, mode);

? Rationale: The man page [1] says

       AT_EMPTY_PATH (since Linux 6.6)
              If path is an empty string, operate on the file referred to
              by dirfd (which may have been obtained using the open(2)
              O_PATH flag).  In this case, dirfd can refer to any type of
              file, not just a directory.  If dirfd is AT_FDCWD, the call
              operates on the current working directory.  This flag is
              Linux-specific; define _GNU_SOURCE to obtain its
              definition.

Bruno

[1] https://man7.org/linux/man-pages/man2/fchmodat.2.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.