Only use O_NOFOLLOW in fchownat and fchmodat if defined

This commit is contained in:
Tim Rice 2019-03-31 19:22:19 -07:00
parent 342d6e5158
commit 43f47ebbdd
1 changed files with 4 additions and 0 deletions

View File

@ -174,8 +174,10 @@ fchownat(int fd, const char *path, uid_t owner, gid_t group, int flag)
# ifndef HAVE_FCHOWN
return chown(pathname, owner, group);
# else
# ifdef O_NOFOLLOW
if (flag & AT_SYMLINK_NOFOLLOW)
oflags |= O_NOFOLLOW;
# endif /* O_NOFOLLOW */
if ((fd = open(path, oflags)) == -1)
return -1;
ret = fchown(fd, owner, group);
@ -203,8 +205,10 @@ fchmodat(int fd, const char *path, mode_t mode, int flag)
# ifndef HAVE_FCHMOD
return chown(pathname, owner, group);
# else
# ifdef O_NOFOLLOW
if (flag & AT_SYMLINK_NOFOLLOW)
oflags |= O_NOFOLLOW;
# endif /* O_NOFOLLOW */
if ((fd = open(path, oflags)) == -1)
return -1;
ret = fchmod(fd, mode);