Skip to content

Commit

Permalink
[CVE-2020-1065] A previous MSRC fix removes the body scope of an encl…
Browse files Browse the repository at this point in the history
…osing 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.
  • Loading branch information
anagoyal authored and rajeshpeter committed May 11, 2020
1 parent 473286e commit e245029
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/Runtime/ByteCode/ScopeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,23 @@ namespace Js
ScopeInfo * scopeInfo = ScopeInfo::SaveScopeInfo(byteCodeGenerator, currentScope, byteCodeGenerator->GetScriptContext());
if (scopeInfo != nullptr)
{
if (funcInfo->root->IsDeclaredInParamScope())
{
FuncInfo* func = byteCodeGenerator->GetEnclosingFuncInfo();
Assert(func);

if (func->IsBodyAndParamScopeMerged())
{
Assert(currentScope == func->GetParamScope() && currentScope->GetScopeType() == ScopeType_Parameter);
Assert(scopeInfo->GetScopeType() == ScopeType_Parameter);
Assert(func->GetBodyScope());

// If the current function is nested in the param scope of it's enclosing function we may have
// skipped the body scope and in may not be the scope stack but the body scope might still be
// in the frame display and we will need to account for it. See ByteCodeGenerateor::FindScopeForSym.
scopeInfo->mustInstantiate = func->GetBodyScope()->GetMustInstantiate();
}
}
funcInfo->byteCodeFunction->SetScopeInfo(scopeInfo);
}
}
Expand Down

0 comments on commit e245029

Please # to comment.