aboutsummaryrefslogtreecommitdiff
path: root/lib/fs.js
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2017-12-25 05:01:11 +0800
committerAnatoli Papirovski <apapirovski@mac.com>2017-12-27 12:47:45 -0500
commit71396a200d75b11a71af7caae18d12f3dc461d07 (patch)
tree795ff91feded0ffd926e3bbc46d75a474627d8c0 /lib/fs.js
parent9ec700b073894ad54432db4c4b540e2b61b45325 (diff)
downloadandroid-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.js7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/fs.js b/lib/fs.js
index e41d0db033..93be375334 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -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;