Skip to content

Commit

Permalink
[CVE-2017-11767] Do not instantiate param scope if only the function …
Browse files Browse the repository at this point in the history
…expression symbol is captured

If a split scope happens because of the function expression being captured then the param scope may not have any locals in closure as the function expression symbol belongs to the function expression scope. In this case we don't have to instantiate the param scope in split scope.
  • Loading branch information
aneeshdk authored and Suwei Chen committed Sep 14, 2017
1 parent b32f19a commit b3e3959
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/Runtime/ByteCode/ByteCodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4219,7 +4219,20 @@ void ByteCodeGenerator::StartEmitFunction(ParseNode *pnodeFnc)
{
bodyScope->SetMustInstantiate(funcInfo->frameSlotsRegister != Js::Constants::NoRegister);
}
paramScope->SetMustInstantiate(!pnodeFnc->sxFnc.IsBodyAndParamScopeMerged());

if (!pnodeFnc->sxFnc.IsBodyAndParamScopeMerged())
{
if (funcInfo->frameObjRegister != Js::Constants::NoRegister)
{
paramScope->SetMustInstantiate(true);
}
else
{
// In the case of function expression being captured in the param scope the hasownlocalinclosure will be false for param scope,
// as function expression symbol stays in the function expression scope. We don't have to set mustinstantiate for param scope in that case.
paramScope->SetMustInstantiate(paramScope->GetHasOwnLocalInClosure());
}
}
}
else
{
Expand Down
8 changes: 8 additions & 0 deletions test/es6/default-splitscope.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ var tests = [
};
f13();

var f14 = function f15(a = (function() {
return f15(1);
})()) {
with({}) {
};
return a === 1 ? 10 : a;
};
assert.areEqual(10, f14(), "Function expresison is captured in the param scope when no other formals are captured");
}
},
{
Expand Down

0 comments on commit b3e3959

Please # to comment.