fs: fix valid id range on chown, lchown, fchown

PR-URL: https://github.com/nodejs/node/pull/31694
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
This commit is contained in:
himself65 authored and Shelley Vohr committed 2020-03-30 11:00:27 -07:00
1 parent 3f1b9162f6
commit de5d162c60
2 files changed
+18 -17

No files matched your search

+15 -14
View File
@@ -102,9 +102,10 @@ const {
parseMode,
validateBuffer,
validateInteger,
validateInt32,
validateUint32
validateInt32
} = require('internal/validators');
// 2 ** 32 - 1
const kMaxUserId = 4294967295;
let truncateWarn = true;
let fs;
@@ -1124,8 +1125,8 @@ function chmodSync(path, mode) {
function lchown(path, uid, gid, callback) {
callback = makeCallback(callback);
path = getValidatedPath(path);
validateUint32(uid, 'uid');
validateUint32(gid, 'gid');
validateInteger(uid, 'uid', -1, kMaxUserId);
validateInteger(gid, 'gid', -1, kMaxUserId);
const req = new FSReqCallback();
req.oncomplete = callback;
binding.lchown(pathModule.toNamespacedPath(path), uid, gid, req);
@@ -1133,8 +1134,8 @@ function lchown(path, uid, gid, callback) {
function lchownSync(path, uid, gid) {
path = getValidatedPath(path);
validateUint32(uid, 'uid');
validateUint32(gid, 'gid');
validateInteger(uid, 'uid', -1, kMaxUserId);
validateInteger(gid, 'gid', -1, kMaxUserId);
const ctx = { path };
binding.lchown(pathModule.toNamespacedPath(path), uid, gid, undefined, ctx);
handleErrorFromBinding(ctx);
@@ -1142,8 +1143,8 @@ function lchownSync(path, uid, gid) {
function fchown(fd, uid, gid, callback) {
validateInt32(fd, 'fd', 0);
validateUint32(uid, 'uid');
validateUint32(gid, 'gid');
validateInteger(uid, 'uid', -1, kMaxUserId);
validateInteger(gid, 'gid', -1, kMaxUserId);
const req = new FSReqCallback();
req.oncomplete = makeCallback(callback);
@@ -1152,8 +1153,8 @@ function fchown(fd, uid, gid, callback) {
function fchownSync(fd, uid, gid) {
validateInt32(fd, 'fd', 0);
validateUint32(uid, 'uid');
validateUint32(gid, 'gid');
validateInteger(uid, 'uid', -1, kMaxUserId);
validateInteger(gid, 'gid', -1, kMaxUserId);
const ctx = {};
binding.fchown(fd, uid, gid, undefined, ctx);
@@ -1163,8 +1164,8 @@ function fchownSync(fd, uid, gid) {
function chown(path, uid, gid, callback) {
callback = makeCallback(callback);
path = getValidatedPath(path);
validateUint32(uid, 'uid');
validateUint32(gid, 'gid');
validateInteger(uid, 'uid', -1, kMaxUserId);
validateInteger(gid, 'gid', -1, kMaxUserId);
const req = new FSReqCallback();
req.oncomplete = callback;
@@ -1173,8 +1174,8 @@ function chown(path, uid, gid, callback) {
function chownSync(path, uid, gid) {
path = getValidatedPath(path);
validateUint32(uid, 'uid');
validateUint32(gid, 'gid');
validateInteger(uid, 'uid', -1, kMaxUserId);
validateInteger(gid, 'gid', -1, kMaxUserId);
const ctx = { path };
binding.chown(pathModule.toNamespacedPath(path), uid, gid, undefined, ctx);
handleErrorFromBinding(ctx);
+3 -3
View File
@@ -44,7 +44,7 @@ function testGid(input, errObj) {
testGid(input, errObj);
});
[-1, 2 ** 32].forEach((input) => {
[-2, 2 ** 32].forEach((input) => {
const errObj = {
code: 'ERR_OUT_OF_RANGE',
name: 'RangeError',
@@ -52,8 +52,8 @@ function testGid(input, errObj) {
`>= 0 && <= 2147483647. Received ${input}`
};
testFd(input, errObj);
errObj.message = 'The value of "uid" is out of range. It must be >= 0 && ' +
`< 4294967296. Received ${input}`;
errObj.message = 'The value of "uid" is out of range. It must be >= -1 && ' +
`<= 4294967295. Received ${input}`;
testUid(input, errObj);
errObj.message = errObj.message.replace('uid', 'gid');
testGid(input, errObj);