Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit db0bb52

Browse filesBrowse files
cjihrigtargos
authored andcommitted
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: #20588 Fixes: #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> Backport-PR-URL: #21172
1 parent 36e5100 commit db0bb52
Copy full SHA for db0bb52

File tree

Expand file treeCollapse file tree

2 files changed

+15
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-5
lines changed
Open diff view settings
Collapse file

‎lib/fs.js‎

Copy file name to clipboardExpand all lines: lib/fs.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const {
8686
isUint32,
8787
validateAndMaskMode,
8888
validateInteger,
89+
validateInt32,
8990
validateUint32
9091
} = require('internal/validators');
9192

@@ -1054,7 +1055,7 @@ fs.unlinkSync = function(path) {
10541055
};
10551056

10561057
fs.fchmod = function(fd, mode, callback) {
1057-
validateUint32(fd, 'fd');
1058+
validateInt32(fd, 'fd', 0);
10581059
mode = validateAndMaskMode(mode, 'mode');
10591060
callback = makeCallback(callback);
10601061

@@ -1064,7 +1065,7 @@ fs.fchmod = function(fd, mode, callback) {
10641065
};
10651066

10661067
fs.fchmodSync = function(fd, mode) {
1067-
validateUint32(fd, 'fd');
1068+
validateInt32(fd, 'fd', 0);
10681069
mode = validateAndMaskMode(mode, 'mode');
10691070
const ctx = {};
10701071
binding.fchmod(fd, mode, undefined, ctx);
Collapse file

‎test/parallel/test-fs-fchmod.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-fchmod.js
+12-3Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,21 @@ const fs = require('fs');
3535
const errObj = {
3636
code: 'ERR_OUT_OF_RANGE',
3737
name: 'RangeError [ERR_OUT_OF_RANGE]',
38-
message: 'The value of "fd" is out of range. It must be >= 0 && < ' +
39-
`${2 ** 32}. Received ${input}`
38+
message: 'The value of "fd" is out of range. It must be >= 0 && <= ' +
39+
`2147483647. Received ${input}`
4040
};
4141
assert.throws(() => fs.fchmod(input), errObj);
4242
assert.throws(() => fs.fchmodSync(input), errObj);
43-
errObj.message = errObj.message.replace('fd', 'mode');
43+
});
44+
45+
[-1, 2 ** 32].forEach((input) => {
46+
const errObj = {
47+
code: 'ERR_OUT_OF_RANGE',
48+
name: 'RangeError [ERR_OUT_OF_RANGE]',
49+
message: 'The value of "mode" is out of range. It must be >= 0 && < ' +
50+
`4294967296. Received ${input}`
51+
};
52+
4453
assert.throws(() => fs.fchmod(1, input), errObj);
4554
assert.throws(() => fs.fchmodSync(1, input), errObj);
4655
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.