Skip to content

Commit 64e7619

Browse files
pleathakroshg
authored andcommitted
[CVE-2018-0936] Incorrect byte code for captured function expression name may lead to OOB - Internal
1 parent 8b229ce commit 64e7619

File tree

5 files changed

+14
-49
lines changed

5 files changed

+14
-49
lines changed

lib/Parser/Parse.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -932,21 +932,6 @@ Symbol* Parser::AddDeclForPid(ParseNodePtr pnode, IdentPtr pid, SymbolType symbo
932932
CheckRedeclarationErrorForBlockId(pid, pnodeFnc->sxFnc.pnodeScopes->sxBlock.blockId);
933933
}
934934

935-
if ((scope->GetScopeType() == ScopeType_FunctionBody || scope->GetScopeType() == ScopeType_Parameter) && symbolType != STFunction)
936-
{
937-
AnalysisAssert(pnodeFnc);
938-
if (pnodeFnc->sxFnc.pnodeName &&
939-
pnodeFnc->sxFnc.pnodeName->nop == knopVarDecl &&
940-
pnodeFnc->sxFnc.pnodeName->sxVar.pid == pid &&
941-
(pnodeFnc->sxFnc.IsBodyAndParamScopeMerged() || scope->GetScopeType() == ScopeType_Parameter))
942-
{
943-
// Named function expression has its name hidden by a local declaration.
944-
// This is important to know if we don't know whether nested deferred functions refer to it,
945-
// because if the name has a non-local reference then we have to create a scope object.
946-
m_currentNodeFunc->sxFnc.SetNameIsHidden();
947-
}
948-
}
949-
950935
if (!sym)
951936
{
952937
const char16 *name = reinterpret_cast<const char16*>(pid->Psz());
@@ -6576,15 +6561,6 @@ bool Parser::ParseFncNames(ParseNodePtr pnodeFnc, ParseNodePtr pnodeFncParent, u
65766561
*pFncNamePid = pidBase;
65776562
}
65786563

6579-
if (fDeclaration &&
6580-
pnodeFncParent &&
6581-
pnodeFncParent->sxFnc.pnodeName &&
6582-
pnodeFncParent->sxFnc.pnodeName->nop == knopVarDecl &&
6583-
pnodeFncParent->sxFnc.pnodeName->sxVar.pid == pidBase)
6584-
{
6585-
pnodeFncParent->sxFnc.SetNameIsHidden();
6586-
}
6587-
65886564
if (buildAST)
65896565
{
65906566
AnalysisAssert(pnodeFnc);

lib/Parser/ptree.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ enum FncFlags : uint
196196
kFunctionIsClassConstructor = 1 << 18, // function is a class constructor
197197
kFunctionIsBaseClassConstructor = 1 << 19, // function is a base class constructor
198198
kFunctionIsClassMember = 1 << 20, // function is a class member
199-
kFunctionNameIsHidden = 1 << 21, // True if a named function expression has its name hidden from nested functions
199+
// Free = 1 << 21,
200200
kFunctionIsGeneratedDefault = 1 << 22, // Is the function generated by us as a default (e.g. default class constructor)
201201
kFunctionHasDefaultArguments = 1 << 23, // Function has one or more ES6 default arguments
202202
kFunctionIsStaticMember = 1 << 24,
@@ -317,7 +317,6 @@ struct PnFnc
317317
void SetIsLambda(bool set = true) { SetFlags(kFunctionIsLambda, set); }
318318
void SetIsMethod(bool set = true) { SetFlags(kFunctionIsMethod, set); }
319319
void SetIsStaticMember(bool set = true) { SetFlags(kFunctionIsStaticMember, set); }
320-
void SetNameIsHidden(bool set = true) { SetFlags(kFunctionNameIsHidden, set); }
321320
void SetNested(bool set = true) { SetFlags(kFunctionNested, set); }
322321
void SetStrictMode(bool set = true) { SetFlags(kFunctionStrictMode, set); }
323322
void SetIsModule(bool set = true) { SetFlags(kFunctionIsModule, set); }
@@ -358,7 +357,6 @@ struct PnFnc
358357
bool IsNested() const { return HasFlags(kFunctionNested); }
359358
bool IsStaticMember() const { return HasFlags(kFunctionIsStaticMember); }
360359
bool IsModule() const { return HasFlags(kFunctionIsModule); }
361-
bool NameIsHidden() const { return HasFlags(kFunctionNameIsHidden); }
362360
bool UsesArguments() const { return HasFlags(kFunctionUsesArguments); }
363361
bool IsDefaultModuleExport() const { return HasFlags(kFunctionIsDefaultModuleExport); }
364362
bool NestedFuncEscapes() const { return nestedFuncEscapes; }
@@ -370,7 +368,6 @@ struct PnFnc
370368
kFunctionNested |
371369
kFunctionDeclaration |
372370
kFunctionStrictMode |
373-
kFunctionNameIsHidden |
374371
kFunctionHasReferenceableBuiltInArguments |
375372
kFunctionHasNonThisStmt |
376373
// todo:: we shouldn't accept kFunctionHasAnyWriteToFormals on the asm module, but it looks like a bug is setting that flag incorrectly

lib/Runtime/ByteCode/ByteCodeGenerator.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,27 +2686,12 @@ FuncInfo* PostVisitFunction(ParseNode* pnode, ByteCodeGenerator* byteCodeGenerat
26862686
Assert(CONFIG_FLAG(DeferNested));
26872687
byteCodeGenerator->ProcessCapturedSym(sym);
26882688

2689-
if (!top->root->sxFnc.NameIsHidden())
2689+
top->SetFuncExprNameReference(true);
2690+
if (pnode->sxFnc.pnodeBody)
26902691
{
2691-
top->SetFuncExprNameReference(true);
2692-
if (pnode->sxFnc.pnodeBody)
2693-
{
2694-
top->GetParsedFunctionBody()->SetFuncExprNameReference(true);
2695-
}
2696-
if (!sym->GetScope()->GetIsObject())
2697-
{
2698-
// The function expression symbol will be emitted in the param/body scope.
2699-
if (top->GetParamScope())
2700-
{
2701-
top->GetParamScope()->SetHasOwnLocalInClosure(true);
2702-
}
2703-
else
2704-
{
2705-
top->GetBodyScope()->SetHasOwnLocalInClosure(true);
2706-
}
2707-
top->SetHasLocalInClosure(true);
2708-
}
2692+
top->GetParsedFunctionBody()->SetFuncExprNameReference(true);
27092693
}
2694+
byteCodeGenerator->ProcessScopeWithCapturedSym(sym->GetScope());
27102695
}
27112696
}
27122697

test/Function/evenMoreFuncExpr3.baseline

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ obj[0].z : proto[0].z
99
obj[0].w : proto[0].w
1010
obj[1].z : undefined
1111
obj[1].w : undefined
12+
pass

test/Function/evenMoreFuncExpr3.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,11 @@ var a = function x() {
4040
"use strict";
4141
x = 1;
4242
};
43-
}
44-
43+
};
44+
45+
(function __f_997(__v_4351 = function () {
46+
WScript.Echo('pass');
47+
return __f_997;
48+
}()) {
49+
function __f_997() {}
50+
})();

0 commit comments

Comments
 (0)