Move the invalid fd check to after checking if fd == AT_FDCWD in the fchownat() function
This commit is contained in:
@@ -206,18 +206,18 @@ fchownat(int fd, const char* path, uid_t owner, gid_t group, int flag)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fd < 0) {
|
|
||||||
// Invalid file descriptor
|
|
||||||
errno = EBADF;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fd == AT_FDCWD || path != NULL && path[0] == '/') {
|
if (fd == AT_FDCWD || path != NULL && path[0] == '/') {
|
||||||
// call chown() ignoring fd
|
// call chown() ignoring fd
|
||||||
return (flag & AT_SYMLINK_NOFOLLOW) != 0 ? lchown(path, owner, group)
|
return (flag & AT_SYMLINK_NOFOLLOW) != 0 ? lchown(path, owner, group)
|
||||||
: chown(path, owner, group);
|
: chown(path, owner, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fd < 0) {
|
||||||
|
// Invalid file descriptor
|
||||||
|
errno = EBADF;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
char *fullPath = (char *)malloc(MAXPATHLEN);
|
char *fullPath = (char *)malloc(MAXPATHLEN);
|
||||||
if (fullPath == NULL) {
|
if (fullPath == NULL) {
|
||||||
// ran out of memory allocating dirpath
|
// ran out of memory allocating dirpath
|
||||||
|
|||||||
Reference in New Issue
Block a user