diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2017-12-25 05:01:11 +0800 |
---|---|---|
committer | Anatoli Papirovski <apapirovski@mac.com> | 2017-12-27 12:47:45 -0500 |
commit | 71396a200d75b11a71af7caae18d12f3dc461d07 (patch) | |
tree | 795ff91feded0ffd926e3bbc46d75a474627d8c0 /lib/fs.js | |
parent | 9ec700b073894ad54432db4c4b540e2b61b45325 (diff) | |
download | android-node-v8-71396a200d75b11a71af7caae18d12f3dc461d07.tar.gz android-node-v8-71396a200d75b11a71af7caae18d12f3dc461d07.tar.bz2 android-node-v8-71396a200d75b11a71af7caae18d12f3dc461d07.zip |
fs: validate path in fs.exists{Sync}
PR-URL: https://github.com/nodejs/node/pull/17852
Refs: https://github.com/nodejs/node/pull/17667
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'lib/fs.js')
-rw-r--r-- | lib/fs.js | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -340,6 +340,10 @@ fs.accessSync = function(path, mode) { fs.exists = function(path, callback) { if (handleError((path = getPathFromURL(path)), cb)) return; + if (typeof path !== 'string' && !(path instanceof Buffer)) { + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'path', + ['string', 'Buffer', 'URL']); + } if (!nullCheck(path, cb)) return; var req = new FSReqWrap(); req.oncomplete = cb; @@ -361,6 +365,9 @@ Object.defineProperty(fs.exists, internalUtil.promisify.custom, { fs.existsSync = function(path) { try { handleError((path = getPathFromURL(path))); + if (typeof path !== 'string' && !(path instanceof Buffer)) { + return false; + } nullCheck(path); binding.stat(pathModule.toNamespacedPath(path)); return true; |