GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs: improve fchmod{Sync} validation · nodejs/node@db0bb52

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • fs.js
  • test/parallel
    • test-fs-fchmod.js
Expand file treeCollapse file tree
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)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.