From 1ffbda8eb49fe5273a08fe89d53ec9de8173133f Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Tue, 9 Oct 2018 16:53:58 -0400 Subject: [PATCH] Avoid unnecessary allocations --- lib/core/fs.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/core/fs.js b/lib/core/fs.js index 7a7e1cf3..5b73f6de 100644 --- a/lib/core/fs.js +++ b/lib/core/fs.js @@ -7,12 +7,16 @@ require('colors'); function restrictPath(receiver, binding, count, args) { const dapp = dappPath(); - const tmp = os.tmpdir(); + const allowedRoots = [ + dapp, + os.tmpdir() + ]; + let allInsideRestricted = true; for(let i = 0; i < count; i++) { let resolved = path.resolve(dapp, args[i]); - allInsideRestricted = [dapp, tmp].some(p => { return resolved.indexOf(p) === 0; }); + allInsideRestricted = allowedRoots.some(p => { return resolved.indexOf(p) === 0; }); if(!allInsideRestricted) break; }