Avoid unnecessary allocations

This commit is contained in:
Andre Medeiros 2018-10-09 16:53:58 -04:00 committed by Pascal Precht
parent 26ff48bb15
commit 1ffbda8eb4
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D

View File

@ -7,12 +7,16 @@ require('colors');
function restrictPath(receiver, binding, count, args) { function restrictPath(receiver, binding, count, args) {
const dapp = dappPath(); const dapp = dappPath();
const tmp = os.tmpdir(); const allowedRoots = [
dapp,
os.tmpdir()
];
let allInsideRestricted = true; let allInsideRestricted = true;
for(let i = 0; i < count; i++) { for(let i = 0; i < count; i++) {
let resolved = path.resolve(dapp, args[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; if(!allInsideRestricted) break;
} }