Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
fs: fix flag and mode validation
The `flag` and `mode` options were not being validated correctly. Signed-off-by: James M Snell <jasnell@gmail.com> Fixes: #37430 PR-URL: #37480 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
- Loading branch information
Showing
with
67 additions
and 43 deletions.
- +2 −1 lib/fs.js
- +2 −1 lib/internal/fs/utils.js
- +4 −14 lib/internal/validators.js
- +39 −0 test/parallel/test-file-validate-mode-flag.js
- +1 −4 test/parallel/test-fs-chmod.js
- +6 −6 test/parallel/test-fs-fchmod.js
- +9 −6 test/parallel/test-fs-lchmod.js
- +3 −6 test/parallel/test-fs-open.js
- +1 −5 test/parallel/test-process-umask.js
| @@ -0,0 +1,39 @@ | ||
| 'use strict'; | ||
|
|
||
| // Checks for crash regression: https://github.com/nodejs/node/issues/37430 | ||
|
|
||
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
| const { | ||
| open, | ||
| openSync, | ||
| promises: { | ||
| open: openPromise, | ||
| }, | ||
| } = require('fs'); | ||
|
|
||
| // These should throw, not crash. | ||
|
|
||
| assert.throws(() => open(__filename, 2176057344, common.mustNotCall()), { | ||
| code: 'ERR_OUT_OF_RANGE' | ||
| }); | ||
|
|
||
| assert.throws(() => open(__filename, 0, 2176057344, common.mustNotCall()), { | ||
| code: 'ERR_OUT_OF_RANGE' | ||
| }); | ||
|
|
||
| assert.throws(() => openSync(__filename, 2176057344), { | ||
| code: 'ERR_OUT_OF_RANGE' | ||
| }); | ||
|
|
||
| assert.throws(() => openSync(__filename, 0, 2176057344), { | ||
| code: 'ERR_OUT_OF_RANGE' | ||
| }); | ||
|
|
||
| assert.rejects(openPromise(__filename, 2176057344), { | ||
| code: 'ERR_OUT_OF_RANGE' | ||
| }); | ||
|
|
||
| assert.rejects(openPromise(__filename, 0, 2176057344), { | ||
| code: 'ERR_OUT_OF_RANGE' | ||
| }); |

