Move the invalid fd check to after checking if fd == AT_FDCWD in the fchownat() function

This commit is contained in:
John Scipione 2012-03-08 17:03:15 -05:00
parent adf4838afe
commit 2f9bd2c090

View File

@ -206,18 +206,18 @@ fchownat(int fd, const char* path, uid_t owner, gid_t group, int flag)
return -1;
}
if (fd < 0) {
// Invalid file descriptor
errno = EBADF;
return -1;
}
if (fd == AT_FDCWD || path != NULL && path[0] == '/') {
// call chown() ignoring fd
return (flag & AT_SYMLINK_NOFOLLOW) != 0 ? lchown(path, owner, group)
: chown(path, owner, group);
}
if (fd < 0) {
// Invalid file descriptor
errno = EBADF;
return -1;
}
char *fullPath = (char *)malloc(MAXPATHLEN);
if (fullPath == NULL) {
// ran out of memory allocating dirpath