Skip to content

Commit e245029

Browse files
anagoyalrajeshpeter
authored andcommitted
[CVE-2020-1065] A previous MSRC fix removes the body scope of an enclosing function when a nested function is declared in the param scope of that enclosing function. This an result in us calculating incorrect envIndex for any symbols captured from enclosing scopes if this skipped body scope appears in the frameDisplay being passed to the nested function. This fix addresses the issue by marking the parameter scope also as mustInstantiate = true so we end up computing the correct envIndex. This problem and the fix only triggers when the enclosing function's param and body scopes are merged so the param and body scopes will never appear together in the scope stack and as such will not mess up the envIndex.
1 parent 473286e commit e245029

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/Runtime/ByteCode/ScopeInfo.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,23 @@ namespace Js
194194
ScopeInfo * scopeInfo = ScopeInfo::SaveScopeInfo(byteCodeGenerator, currentScope, byteCodeGenerator->GetScriptContext());
195195
if (scopeInfo != nullptr)
196196
{
197+
if (funcInfo->root->IsDeclaredInParamScope())
198+
{
199+
FuncInfo* func = byteCodeGenerator->GetEnclosingFuncInfo();
200+
Assert(func);
201+
202+
if (func->IsBodyAndParamScopeMerged())
203+
{
204+
Assert(currentScope == func->GetParamScope() && currentScope->GetScopeType() == ScopeType_Parameter);
205+
Assert(scopeInfo->GetScopeType() == ScopeType_Parameter);
206+
Assert(func->GetBodyScope());
207+
208+
// If the current function is nested in the param scope of it's enclosing function we may have
209+
// skipped the body scope and in may not be the scope stack but the body scope might still be
210+
// in the frame display and we will need to account for it. See ByteCodeGenerateor::FindScopeForSym.
211+
scopeInfo->mustInstantiate = func->GetBodyScope()->GetMustInstantiate();
212+
}
213+
}
197214
funcInfo->byteCodeFunction->SetScopeInfo(scopeInfo);
198215
}
199216
}

0 commit comments

Comments
 (0)