fs: improve fchmod{Sync} validation
This commit validates the fd parameters to fs.fchmod{Sync} as int32s instead of uint32s because they are ints in the binding layer. PR-URL: https://github.com/nodejs/node/pull/20588 Fixes: https://github.com/nodejs/node/issues/20498 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
1c1b8ae409
commit
1ae184a85c
@ -1057,7 +1057,7 @@ fs.unlinkSync = function(path) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fs.fchmod = function(fd, mode, callback) {
|
fs.fchmod = function(fd, mode, callback) {
|
||||||
validateUint32(fd, 'fd');
|
validateInt32(fd, 'fd', 0);
|
||||||
mode = validateAndMaskMode(mode, 'mode');
|
mode = validateAndMaskMode(mode, 'mode');
|
||||||
callback = makeCallback(callback);
|
callback = makeCallback(callback);
|
||||||
|
|
||||||
@ -1067,7 +1067,7 @@ fs.fchmod = function(fd, mode, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fs.fchmodSync = function(fd, mode) {
|
fs.fchmodSync = function(fd, mode) {
|
||||||
validateUint32(fd, 'fd');
|
validateInt32(fd, 'fd', 0);
|
||||||
mode = validateAndMaskMode(mode, 'mode');
|
mode = validateAndMaskMode(mode, 'mode');
|
||||||
const ctx = {};
|
const ctx = {};
|
||||||
binding.fchmod(fd, mode, undefined, ctx);
|
binding.fchmod(fd, mode, undefined, ctx);
|
||||||
|
@ -35,12 +35,21 @@ const fs = require('fs');
|
|||||||
const errObj = {
|
const errObj = {
|
||||||
code: 'ERR_OUT_OF_RANGE',
|
code: 'ERR_OUT_OF_RANGE',
|
||||||
name: 'RangeError [ERR_OUT_OF_RANGE]',
|
name: 'RangeError [ERR_OUT_OF_RANGE]',
|
||||||
message: 'The value of "fd" is out of range. It must be >= 0 && < ' +
|
message: 'The value of "fd" is out of range. It must be >= 0 && <= ' +
|
||||||
`${2 ** 32}. Received ${input}`
|
`2147483647. Received ${input}`
|
||||||
};
|
};
|
||||||
assert.throws(() => fs.fchmod(input), errObj);
|
assert.throws(() => fs.fchmod(input), errObj);
|
||||||
assert.throws(() => fs.fchmodSync(input), errObj);
|
assert.throws(() => fs.fchmodSync(input), errObj);
|
||||||
errObj.message = errObj.message.replace('fd', 'mode');
|
});
|
||||||
|
|
||||||
|
[-1, 2 ** 32].forEach((input) => {
|
||||||
|
const errObj = {
|
||||||
|
code: 'ERR_OUT_OF_RANGE',
|
||||||
|
name: 'RangeError [ERR_OUT_OF_RANGE]',
|
||||||
|
message: 'The value of "mode" is out of range. It must be >= 0 && < ' +
|
||||||
|
`4294967296. Received ${input}`
|
||||||
|
};
|
||||||
|
|
||||||
assert.throws(() => fs.fchmod(1, input), errObj);
|
assert.throws(() => fs.fchmod(1, input), errObj);
|
||||||
assert.throws(() => fs.fchmodSync(1, input), errObj);
|
assert.throws(() => fs.fchmodSync(1, input), errObj);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user