diff --git a/lib/fs.js b/lib/fs.js index 57ab470f3e78a3..3103c71475deb5 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -2022,6 +2022,9 @@ function fchown(fd, uid, gid, callback) { * @returns {void} */ function fchownSync(fd, uid, gid) { + fd = getValidatedFd(fd); + validateInteger(uid, 'uid', -1, kMaxUserId); + validateInteger(gid, 'gid', -1, kMaxUserId); return syncFs.fchown(fd, uid, gid); } diff --git a/lib/internal/fs/sync.js b/lib/internal/fs/sync.js index 669871e1d6496d..4eaae92a77b868 100644 --- a/lib/internal/fs/sync.js +++ b/lib/internal/fs/sync.js @@ -9,7 +9,7 @@ const { getStatFsFromBinding, getValidatedFd, } = require('internal/fs/utils'); -const { parseFileMode, isInt32, validateInteger } = require('internal/validators'); +const { parseFileMode, isInt32 } = require('internal/validators'); const binding = internalBinding('fs'); @@ -94,9 +94,6 @@ function unlink(path) { } function fchown(fd, uid, gid) { - fd = getValidatedFd(fd); - validateInteger(uid, 'uid', -1); - validateInteger(gid, 'gid', -1); return binding.fchownSync(fd, uid, gid); } diff --git a/src/node_file.cc b/src/node_file.cc index e047d965e56cd9..98446a678ea2a5 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -2814,7 +2814,7 @@ static void FChownSync(const FunctionCallbackInfo& args) { CHECK_GE(argc, 3); CHECK(args[0]->IsInt32()); - const uv_gid_t fd = static_cast(args[0].As()->Value()); + const uv_file fd = static_cast(args[0].As()->Value()); CHECK(args[1]->IsInt32()); const uv_uid_t uid = static_cast(args[1].As()->Value());