From 2f9bd2c0905da9df770b1a6083fb59a13a4c97da Mon Sep 17 00:00:00 2001 From: John Scipione Date: Thu, 8 Mar 2012 17:03:15 -0500 Subject: [PATCH] Move the invalid fd check to after checking if fd == AT_FDCWD in the fchownat() function --- src/build/libroot/fs_darwin.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/build/libroot/fs_darwin.cpp b/src/build/libroot/fs_darwin.cpp index 6b9ab675bd..23f45e25ff 100644 --- a/src/build/libroot/fs_darwin.cpp +++ b/src/build/libroot/fs_darwin.cpp @@ -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