| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7c63bc6 commit da217d0
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -347,7 +347,7 @@ function readFile(path, options, callback) { | |||
| 347 | 347 | return; | |
| 348 | 348 | } | |
| 349 | 349 | ||
| 350 | - const flagsNumber = stringToFlags(options.flag); | ||
| 350 | + const flagsNumber = stringToFlags(options.flag, 'options.flag'); | ||
| 351 | 351 | path = getValidatedPath(path); | |
| 352 | 352 | ||
| 353 | 353 | const req = new FSReqCallback(); | |
@@ -1284,6 +1284,7 @@ function fchmodSync(fd, mode) { | |||
| 1284 | 1284 | ||
| 1285 | 1285 | function lchmod(path, mode, callback) { | |
| 1286 | 1286 | callback = maybeCallback(callback); | |
| 1287 | + mode = parseFileMode(mode, 'mode'); | ||
| 1287 | 1288 | fs.open(path, O_WRONLY | O_SYMLINK, (err, fd) => { | |
| 1288 | 1289 | if (err) { | |
| 1289 | 1290 | callback(err); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -526,8 +526,9 @@ function getStatsFromBinding(stats, offset = 0) { | |||
| 526 | 526 | ); | |
| 527 | 527 | } | |
| 528 | 528 | ||
| 529 | - function stringToFlags(flags) { | ||
| 529 | + function stringToFlags(flags, name = 'flags') { | ||
| 530 | 530 | if (typeof flags === 'number') { | |
| 531 | + validateInt32(flags, name); | ||
| 531 | 532 | return flags; | |
| 532 | 533 | } | |
| 533 | 534 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,26 +56,16 @@ const modeDesc = 'must be a 32-bit unsigned integer or an octal string'; | |||
| 56 | 56 | * @returns {number} | |
| 57 | 57 | */ | |
| 58 | 58 | function parseFileMode(value, name, def) { | |
| 59 | - if (value == null && def !== undefined) { | ||
| 60 | - return def; | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - if (isUint32(value)) { | ||
| 64 | - return value; | ||
| 65 | - } | ||
| 66 | - | ||
| 67 | - if (typeof value === 'number') { | ||
| 68 | - validateInt32(value, name, 0, 2 ** 32 - 1); | ||
| 69 | - } | ||
| 70 | - | ||
| 59 | + value ??= def; | ||
| 71 | 60 | if (typeof value === 'string') { | |
| 72 | 61 | if (!RegExpPrototypeTest(octalReg, value)) { | |
| 73 | 62 | throw new ERR_INVALID_ARG_VALUE(name, value, modeDesc); | |
| 74 | 63 | } | |
| 75 | - return NumberParseInt(value, 8); | ||
| 64 | + value = NumberParseInt(value, 8); | ||
| 76 | 65 | } | |
| 77 | 66 | ||
| 78 | - throw new ERR_INVALID_ARG_VALUE(name, value, modeDesc); | ||
| 67 | + validateInt32(value, name, 0, 2 ** 32 - 1); | ||
| 68 | + return value; | ||
| 79 | 69 | } | |
| 80 | 70 | ||
| 81 | 71 | const validateInteger = hideStackFrames( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,39 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // Checks for crash regression: https://github.com/nodejs/node/issues/37430 | ||
| 4 | + | ||
| 5 | + const common = require('../common'); | ||
| 6 | + const assert = require('assert'); | ||
| 7 | + const { | ||
| 8 | + open, | ||
| 9 | + openSync, | ||
| 10 | + promises: { | ||
| 11 | + open: openPromise, | ||
| 12 | + }, | ||
| 13 | + } = require('fs'); | ||
| 14 | + | ||
| 15 | + // These should throw, not crash. | ||
| 16 | + | ||
| 17 | + assert.throws(() => open(__filename, 2176057344, common.mustNotCall()), { | ||
| 18 | + code: 'ERR_OUT_OF_RANGE' | ||
| 19 | + }); | ||
| 20 | + | ||
| 21 | + assert.throws(() => open(__filename, 0, 2176057344, common.mustNotCall()), { | ||
| 22 | + code: 'ERR_OUT_OF_RANGE' | ||
| 23 | + }); | ||
| 24 | + | ||
| 25 | + assert.throws(() => openSync(__filename, 2176057344), { | ||
| 26 | + code: 'ERR_OUT_OF_RANGE' | ||
| 27 | + }); | ||
| 28 | + | ||
| 29 | + assert.throws(() => openSync(__filename, 0, 2176057344), { | ||
| 30 | + code: 'ERR_OUT_OF_RANGE' | ||
| 31 | + }); | ||
| 32 | + | ||
| 33 | + assert.rejects(openPromise(__filename, 2176057344), { | ||
| 34 | + code: 'ERR_OUT_OF_RANGE' | ||
| 35 | + }); | ||
| 36 | + | ||
| 37 | + assert.rejects(openPromise(__filename, 0, 2176057344), { | ||
| 38 | + code: 'ERR_OUT_OF_RANGE' | ||
| 39 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -106,10 +106,7 @@ fs.open(file2, 'w', common.mustSucceed((fd) => { | |||
| 106 | 106 | assert.throws( | |
| 107 | 107 | () => fs.fchmod(fd, {}), | |
| 108 | 108 | { | |
| 109 | - code: 'ERR_INVALID_ARG_VALUE', | ||
| 110 | - name: 'TypeError', | ||
| 111 | - message: 'The argument \'mode\' must be a 32-bit unsigned integer ' + | ||
| 112 | - 'or an octal string. Received {}' | ||
| 109 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 113 | 110 | } | |
| 114 | 111 | ); | |
| 115 | 112 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,6 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | const common = require('../common'); | |
| 3 | 3 | const assert = require('assert'); | |
| 4 | - const util = require('util'); | ||
| 5 | 4 | const fs = require('fs'); | |
| 6 | 5 | ||
| 7 | 6 | // This test ensures that input for fchmod is valid, testing for valid | |
@@ -20,17 +19,18 @@ const fs = require('fs'); | |||
| 20 | 19 | }); | |
| 21 | 20 | ||
| 22 | 21 | ||
| 23 | - [false, null, undefined, {}, [], '', '123x'].forEach((input) => { | ||
| 22 | + [false, null, {}, []].forEach((input) => { | ||
| 24 | 23 | const errObj = { | |
| 25 | - code: 'ERR_INVALID_ARG_VALUE', | ||
| 26 | - name: 'TypeError', | ||
| 27 | - message: 'The argument \'mode\' must be a 32-bit unsigned integer or an ' + | ||
| 28 | - `octal string. Received ${util.inspect(input)}` | ||
| 24 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 29 | 25 | }; | |
| 30 | 26 | assert.throws(() => fs.fchmod(1, input), errObj); | |
| 31 | 27 | assert.throws(() => fs.fchmodSync(1, input), errObj); | |
| 32 | 28 | }); | |
| 33 | 29 | ||
| 30 | + assert.throws(() => fs.fchmod(1, '123x'), { | ||
| 31 | + code: 'ERR_INVALID_ARG_VALUE' | ||
| 32 | + }); | ||
| 33 | + | ||
| 34 | 34 | [-1, 2 ** 32].forEach((input) => { | |
| 35 | 35 | const errObj = { | |
| 36 | 36 | code: 'ERR_OUT_OF_RANGE', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,6 @@ | |||
| 2 | 2 | ||
| 3 | 3 | const common = require('../common'); | |
| 4 | 4 | const assert = require('assert'); | |
| 5 | - const util = require('util'); | ||
| 6 | 5 | const fs = require('fs'); | |
| 7 | 6 | const { promises } = fs; | |
| 8 | 7 | const f = __filename; | |
@@ -38,18 +37,22 @@ assert.throws(() => fs.lchmod(f, {}), { code: 'ERR_INVALID_CALLBACK' }); | |||
| 38 | 37 | }); | |
| 39 | 38 | ||
| 40 | 39 | // Check mode | |
| 41 | - [false, null, undefined, {}, [], '', '123x'].forEach((input) => { | ||
| 40 | + [false, null, {}, []].forEach((input) => { | ||
| 42 | 41 | const errObj = { | |
| 43 | - code: 'ERR_INVALID_ARG_VALUE', | ||
| 44 | - name: 'TypeError', | ||
| 45 | - message: 'The argument \'mode\' must be a 32-bit unsigned integer or an ' + | ||
| 46 | - `octal string. Received ${util.inspect(input)}` | ||
| 42 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 47 | 43 | }; | |
| 48 | 44 | ||
| 49 | 45 | assert.rejects(promises.lchmod(f, input, () => {}), errObj); | |
| 50 | 46 | assert.throws(() => fs.lchmodSync(f, input), errObj); | |
| 51 | 47 | }); | |
| 52 | 48 | ||
| 49 | + assert.throws(() => fs.lchmod(f, '123x', common.mustNotCall()), { | ||
| 50 | + code: 'ERR_INVALID_ARG_VALUE' | ||
| 51 | + }); | ||
| 52 | + assert.throws(() => fs.lchmodSync(f, '123x'), { | ||
| 53 | + code: 'ERR_INVALID_ARG_VALUE' | ||
| 54 | + }); | ||
| 55 | + | ||
| 53 | 56 | [-1, 2 ** 32].forEach((input) => { | |
| 54 | 57 | const errObj = { | |
| 55 | 58 | code: 'ERR_OUT_OF_RANGE', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -102,22 +102,19 @@ for (const extra of [[], ['r'], ['r', 0], ['r', 0, 'bad callback']]) { | |||
| 102 | 102 | assert.throws( | |
| 103 | 103 | () => fs.open(__filename, 'r', mode, common.mustNotCall()), | |
| 104 | 104 | { | |
| 105 | - message: /'mode' must be a 32-bit/, | ||
| 106 | - code: 'ERR_INVALID_ARG_VALUE' | ||
| 105 | + code: 'ERR_INVALID_ARG_TYPE' | ||
| 107 | 106 | } | |
| 108 | 107 | ); | |
| 109 | 108 | assert.throws( | |
| 110 | 109 | () => fs.openSync(__filename, 'r', mode, common.mustNotCall()), | |
| 111 | 110 | { | |
| 112 | - message: /'mode' must be a 32-bit/, | ||
| 113 | - code: 'ERR_INVALID_ARG_VALUE' | ||
| 111 | + code: 'ERR_INVALID_ARG_TYPE' | ||
| 114 | 112 | } | |
| 115 | 113 | ); | |
| 116 | 114 | assert.rejects( | |
| 117 | 115 | fs.promises.open(__filename, 'r', mode), | |
| 118 | 116 | { | |
| 119 | - message: /'mode' must be a 32-bit/, | ||
| 120 | - code: 'ERR_INVALID_ARG_VALUE' | ||
| 117 | + code: 'ERR_INVALID_ARG_TYPE' | ||
| 121 | 118 | } | |
| 122 | 119 | ); | |
| 123 | 120 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,17 +53,13 @@ assert.strictEqual(process.umask(), old); | |||
| 53 | 53 | assert.throws(() => { | |
| 54 | 54 | process.umask({}); | |
| 55 | 55 | }, { | |
| 56 | - code: 'ERR_INVALID_ARG_VALUE', | ||
| 57 | - message: 'The argument \'mask\' must be a 32-bit unsigned integer ' + | ||
| 58 | - 'or an octal string. Received {}' | ||
| 56 | + code: 'ERR_INVALID_ARG_TYPE', | ||
| 59 | 57 | }); | |
| 60 | 58 | ||
| 61 | 59 | ['123x', 'abc', '999'].forEach((value) => { | |
| 62 | 60 | assert.throws(() => { | |
| 63 | 61 | process.umask(value); | |
| 64 | 62 | }, { | |
| 65 | 63 | code: 'ERR_INVALID_ARG_VALUE', | |
| 66 | - message: 'The argument \'mask\' must be a 32-bit unsigned integer ' + | ||
| 67 | - `or an octal string. Received '${value}'` | ||
| 68 | 64 | }); | |
| 69 | 65 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments