Skip to content

Commit

Permalink
[CVE-2017-11862] [ChakraCore] Type confusion in module exports - Indi…
Browse files Browse the repository at this point in the history
…vidual

Export was not taking care of destructuring nodes, leading to type confusion. Fixed that by adding support for walking those nodes.
  • Loading branch information
akroshg authored and leirocks committed Nov 14, 2017
1 parent 3f8cc2d commit 66d733b
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/Parser/Parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2505,7 +2505,7 @@ ModuleImportOrExportEntry* Parser::AddModuleImportOrExportEntry(ModuleImportOrEx

void Parser::AddModuleLocalExportEntry(ParseNodePtr varDeclNode)
{
Assert(varDeclNode->nop == knopVarDecl || varDeclNode->nop == knopLetDecl || varDeclNode->nop == knopConstDecl);
AssertOrFailFast(varDeclNode->nop == knopVarDecl || varDeclNode->nop == knopLetDecl || varDeclNode->nop == knopConstDecl);

IdentPtr localName = varDeclNode->sxVar.pid;
varDeclNode->sxVar.sym->SetIsModuleExportStorage(true);
Expand Down Expand Up @@ -3014,15 +3014,19 @@ ParseNodePtr Parser::ParseExportDeclaration(bool *needTerminator)

if (buildAST)
{
ParseNodePtr temp = pnode;
while (temp->nop == knopList)
{
ParseNodePtr varDeclNode = temp->sxBin.pnode1;
temp = temp->sxBin.pnode2;

AddModuleLocalExportEntry(varDeclNode);
}
AddModuleLocalExportEntry(temp);
ForEachItemInList(pnode, [&](ParseNodePtr item) {
if (item->nop == knopAsg)
{
Parser::MapBindIdentifier(item, [&](ParseNodePtr subItem)
{
AddModuleLocalExportEntry(subItem);
});
}
else
{
AddModuleLocalExportEntry(item);
}
});
}
}
break;
Expand Down Expand Up @@ -12966,6 +12970,7 @@ ParseNodePtr Parser::ParseDestructuredInitializer(ParseNodePtr lhsNode,
pnodeDestructAsg = CreateNodeWithScanner<knopAsg>();
pnodeDestructAsg->sxBin.pnode1 = lhsNode;
pnodeDestructAsg->sxBin.pnode2 = pnodeDefault;
pnodeDestructAsg->sxBin.pnodeNext = nullptr;
pnodeDestructAsg->ichMin = lhsNode->ichMin;
pnodeDestructAsg->ichLim = pnodeDefault->ichLim;
}
Expand Down

0 comments on commit 66d733b

Please sign in to comment.