diff options
author | Darshan Sen <raisinten@gmail.com> | 2021-03-31 16:14:52 +0300 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2021-05-01 13:25:32 +0300 |
commit | 85987450df87aaf74fd70b6106d3ace43d3d4762 (patch) | |
tree | 9fb629f974ef1b2daa6e478cde1eb9b38ba72581 /lib | |
parent | 21bc5d4bd4aed43f38bd457173d9e84600c4bbae (diff) |
fs: fix chown abort
This syncs the type assertion introduced in the referenced PR in the C++
side. Since chown, lchown, and fchown can accept -1 as a value for uid
and gid, we should also accept signed integers from the JS side.
Fixes: https://github.com/nodejs/node/issues/37995
Refs: https://github.com/nodejs/node/pull/31694
PR-URL: https://github.com/nodejs/node/pull/38004
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/fs/promises.js | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index d989f8818ca..7b2c526b598 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -9,6 +9,9 @@ const kIoMaxLength = 2 ** 31 - 1; const kReadFileMaxChunkSize = 2 ** 14; const kWriteFileMaxChunkSize = 2 ** 14; +// 2 ** 32 - 1 +const kMaxUserId = 4294967295; + const { Error, MathMax, @@ -66,7 +69,6 @@ const { validateAbortSignal, validateBuffer, validateInteger, - validateUint32 } = require('internal/validators'); const pathModule = require('path'); const { promisify } = require('internal/util'); @@ -580,22 +582,22 @@ async function lchmod(path, mode) { async function lchown(path, uid, gid) { path = getValidatedPath(path); - validateUint32(uid, 'uid'); - validateUint32(gid, 'gid'); + validateInteger(uid, 'uid', -1, kMaxUserId); + validateInteger(gid, 'gid', -1, kMaxUserId); return binding.lchown(pathModule.toNamespacedPath(path), uid, gid, kUsePromises); } async function fchown(handle, uid, gid) { - validateUint32(uid, 'uid'); - validateUint32(gid, 'gid'); + validateInteger(uid, 'uid', -1, kMaxUserId); + validateInteger(gid, 'gid', -1, kMaxUserId); return binding.fchown(handle.fd, uid, gid, kUsePromises); } async function chown(path, uid, gid) { path = getValidatedPath(path); - validateUint32(uid, 'uid'); - validateUint32(gid, 'gid'); + validateInteger(uid, 'uid', -1, kMaxUserId); + validateInteger(gid, 'gid', -1, kMaxUserId); return binding.chown(pathModule.toNamespacedPath(path), uid, gid, kUsePromises); } |