Skip to content

Commit

Permalink
Merge pull request #407 from XmiliaH/fix-404-406
Browse files Browse the repository at this point in the history
Fix arguments access on non functions and findBestExtensionHandler.
  • Loading branch information
XmiliaH committed Feb 15, 2022
2 parents 4541794 + c7a972f commit 777ffb0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
v3.9.8 (TBD)
-------------------
[fix] Add function typecheck for arguments, caller, and callee property check (GeoffRen)
[fix] Fix find best extension handler

v3.9.7 (2022-02-10)
-------------------
[fix] Allow relative require from base script
Expand Down
4 changes: 3 additions & 1 deletion lib/bridge.js
Expand Up @@ -431,7 +431,9 @@ function createBridge(otherInit, registerProxy) {
case 'arguments':
case 'caller':
case 'callee':
if (thisOtherHasOwnProperty(object, key)) throw thisThrowCallerCalleeArgumentsAccess(key);
if (typeof object === 'function' && thisOtherHasOwnProperty(object, key)) {
throw thisThrowCallerCalleeArgumentsAccess(key);
}
break;
}
let ret; // @other(unsafe)
Expand Down
4 changes: 2 additions & 2 deletions lib/nodevm.js
Expand Up @@ -405,9 +405,9 @@ class NodeVM extends VM {
}
}
const prefix = strict ? STRICT_MODULE_PREFIX : MODULE_PREFIX;
let scriptCode = prefix + this._compiler(code, unresolvedFilename) + MODULE_SUFFIX;
let scriptCode = this._compiler(code, unresolvedFilename);
scriptCode = transformer(null, scriptCode, false, false).code;
script = new Script(scriptCode, {
script = new Script(prefix + scriptCode + MODULE_SUFFIX, {
__proto__: null,
filename: unresolvedFilename,
displayErrors: false
Expand Down
2 changes: 1 addition & 1 deletion lib/setup-node-sandbox.js
Expand Up @@ -148,7 +148,7 @@ Module._cache = {__proto__: null};
function findBestExtensionHandler(filename) {
const name = resolver.pathBasename(filename);
for (let i = 0; (i = localStringPrototypeIndexOf(name, '.', i + 1)) !== -1;) {
const ext = localStringPrototypeSlice(name, i + 1);
const ext = localStringPrototypeSlice(name, i);
const handler = Module._extensions[ext];
if (handler) return handler;
}
Expand Down
3 changes: 2 additions & 1 deletion test/nodevm.js
Expand Up @@ -77,7 +77,8 @@ describe('modules', () => {
it('require json', () => {
const vm = new NodeVM({
require: {
external: true
external: true,
context: 'sandbox'
}
});

Expand Down
4 changes: 4 additions & 0 deletions test/vm.js
Expand Up @@ -380,6 +380,10 @@ describe('contextify', () => {
}
});

it('arguments', () => {
assert.doesNotThrow(() => vm.run('(o) => o.arguments')({arguments: 1}));
});

after(() => {
vm = null;
});
Expand Down

0 comments on commit 777ffb0

Please sign in to comment.