Skip to content

Commit b3e3959

Browse files
aneeshdkSuwei Chen
authored andcommitted
[CVE-2017-11767] Do not instantiate param scope if only the function 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.
1 parent b32f19a commit b3e3959

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/Runtime/ByteCode/ByteCodeEmitter.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4219,7 +4219,20 @@ void ByteCodeGenerator::StartEmitFunction(ParseNode *pnodeFnc)
42194219
{
42204220
bodyScope->SetMustInstantiate(funcInfo->frameSlotsRegister != Js::Constants::NoRegister);
42214221
}
4222-
paramScope->SetMustInstantiate(!pnodeFnc->sxFnc.IsBodyAndParamScopeMerged());
4222+
4223+
if (!pnodeFnc->sxFnc.IsBodyAndParamScopeMerged())
4224+
{
4225+
if (funcInfo->frameObjRegister != Js::Constants::NoRegister)
4226+
{
4227+
paramScope->SetMustInstantiate(true);
4228+
}
4229+
else
4230+
{
4231+
// In the case of function expression being captured in the param scope the hasownlocalinclosure will be false for param scope,
4232+
// as function expression symbol stays in the function expression scope. We don't have to set mustinstantiate for param scope in that case.
4233+
paramScope->SetMustInstantiate(paramScope->GetHasOwnLocalInClosure());
4234+
}
4235+
}
42234236
}
42244237
else
42254238
{

test/es6/default-splitscope.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ var tests = [
186186
};
187187
f13();
188188

189+
var f14 = function f15(a = (function() {
190+
return f15(1);
191+
})()) {
192+
with({}) {
193+
};
194+
return a === 1 ? 10 : a;
195+
};
196+
assert.areEqual(10, f14(), "Function expresison is captured in the param scope when no other formals are captured");
189197
}
190198
},
191199
{

0 commit comments

Comments
 (0)