diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-05-09 22:44:44 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-05-17 17:14:35 +0800 |
commit | a18e130e597c3efc1df7bd86198c2b5762d4fbae (patch) | |
tree | 584b4e8b5c5a67a3272f2e66646de497777e4dc4 /lib/internal/fs/promises.js | |
parent | 0d9500daedbb61770359c34383a8d4784bcabd56 (diff) | |
download | android-node-v8-a18e130e597c3efc1df7bd86198c2b5762d4fbae.tar.gz android-node-v8-a18e130e597c3efc1df7bd86198c2b5762d4fbae.tar.bz2 android-node-v8-a18e130e597c3efc1df7bd86198c2b5762d4fbae.zip |
lib: mask mode_t type of arguments with 0o777
- Introduce the `validateAndMaskMode` validator that
validates `mode_t` arguments and mask them with 0o777
if they are 32-bit unsigned integer or octal string
to be more consistent with POSIX APIs.
- Use the validator in fs APIs and process.umask for
consistency.
- Add tests for 32-bit unsigned modes larger than 0o777.
PR-URL: https://github.com/nodejs/node/pull/20636
Fixes: https://github.com/nodejs/node/issues/20498
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Diffstat (limited to 'lib/internal/fs/promises.js')
-rw-r--r-- | lib/internal/fs/promises.js | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index 59b46c986c..ee985761ac 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -12,8 +12,7 @@ const { Buffer, kMaxLength } = require('buffer'); const { ERR_FS_FILE_TOO_LARGE, ERR_INVALID_ARG_TYPE, - ERR_METHOD_NOT_IMPLEMENTED, - ERR_OUT_OF_RANGE + ERR_METHOD_NOT_IMPLEMENTED } = require('internal/errors').codes; const { getPathFromURL } = require('internal/url'); const { isUint8Array } = require('internal/util/types'); @@ -21,7 +20,6 @@ const { copyObject, getOptions, getStatsFromBinding, - modeNum, nullCheck, preprocessSymlinkDestination, stringToFlags, @@ -34,6 +32,7 @@ const { } = require('internal/fs/utils'); const { isUint32, + validateAndMaskMode, validateInt32, validateUint32 } = require('internal/validators'); @@ -191,10 +190,9 @@ async function copyFile(src, dest, flags) { // Note that unlike fs.open() which uses numeric file descriptors, // fsPromises.open() uses the fs.FileHandle class. async function open(path, flags, mode) { - mode = modeNum(mode, 0o666); path = getPathFromURL(path); validatePath(path); - validateUint32(mode, 'mode'); + mode = validateAndMaskMode(mode, 'mode', 0o666); return new FileHandle( await binding.openFileHandle(pathModule.toNamespacedPath(path), stringToFlags(flags), @@ -287,10 +285,9 @@ async function fsync(handle) { } async function mkdir(path, mode) { - mode = modeNum(mode, 0o777); path = getPathFromURL(path); validatePath(path); - validateUint32(mode, 'mode'); + mode = validateAndMaskMode(mode, 'mode', 0o777); return binding.mkdir(pathModule.toNamespacedPath(path), mode, kUsePromises); } @@ -361,19 +358,15 @@ async function unlink(path) { } async function fchmod(handle, mode) { - mode = modeNum(mode); validateFileHandle(handle); - validateUint32(mode, 'mode'); - if (mode > 0o777) - throw new ERR_OUT_OF_RANGE('mode', undefined, mode); + mode = validateAndMaskMode(mode, 'mode'); return binding.fchmod(handle.fd, mode, kUsePromises); } async function chmod(path, mode) { path = getPathFromURL(path); validatePath(path); - mode = modeNum(mode); - validateUint32(mode, 'mode'); + mode = validateAndMaskMode(mode, 'mode'); return binding.chmod(pathModule.toNamespacedPath(path), mode, kUsePromises); } |