Changeset 207684 in webkit


Ignore:
Timestamp:
Oct 21, 2016 10:49:30 AM (8 years ago)
Author:
caitp@igalia.com
Message:

[JSC] don't crash when arguments to new Function() produce unexpected AST
https://bugs.webkit.org/show_bug.cgi?id=163748

Reviewed by Mark Lam.

JSTests:

  • stress/regress-163748.js: Added.

(assert):
(shouldThrowSyntaxError):
(GeneratorFunction):

Source/JavaScriptCore:

The ASSERT(statement); and ASSERT(funcDecl); lines are removed, replaced with blocks
to report a generic Parser error message. These lines are only possible to be reached
if the input string produced an unexpected AST, which previously could be used to crash
the process via ASSERT failure.

The node type assertions are left in the tree, as it should be impossible for a top-level
{ to produce anything other than a Block node. If the node turns out not to be a Block,
it indicates that the (C++) caller of this function (E.g in FunctionConstructor.cpp), is
doing something incorrect. Similarly, it should be impossible for the funcDecl node to
be anything other than a function declaration given the conventions of the caller of this
function.

  • runtime/CodeCache.cpp:

(JSC::CodeCache::getFunctionExecutableFromGlobalCode):

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r207671 r207684  
     12016-10-21  Caitlin Potter  <caitp@igalia.com>
     2
     3        [JSC] don't crash when arguments to `new Function()` produce unexpected AST
     4        https://bugs.webkit.org/show_bug.cgi?id=163748
     5
     6        Reviewed by Mark Lam.
     7
     8        * stress/regress-163748.js: Added.
     9        (assert):
     10        (shouldThrowSyntaxError):
     11        (GeneratorFunction):
     12
    1132016-10-20  Keith Miller  <keith_miller@apple.com>
    214
  • trunk/Source/JavaScriptCore/ChangeLog

    r207671 r207684  
     12016-10-21  Caitlin Potter  <caitp@igalia.com>
     2
     3        [JSC] don't crash when arguments to `new Function()` produce unexpected AST
     4        https://bugs.webkit.org/show_bug.cgi?id=163748
     5
     6        Reviewed by Mark Lam.
     7
     8        The ASSERT(statement); and ASSERT(funcDecl); lines are removed, replaced with blocks
     9        to report a generic Parser error message. These lines are only possible to be reached
     10        if the input string produced an unexpected AST, which previously could be used to crash
     11        the process via ASSERT failure.
     12
     13        The node type assertions are left in the tree, as it should be impossible for a top-level
     14        `{` to produce anything other than a Block node. If the node turns out not to be a Block,
     15        it indicates that the (C++) caller of this function (E.g in FunctionConstructor.cpp), is
     16        doing something incorrect. Similarly, it should be impossible for the `funcDecl` node to
     17        be anything other than a function declaration given the conventions of the caller of this
     18        function.
     19
     20        * runtime/CodeCache.cpp:
     21        (JSC::CodeCache::getFunctionExecutableFromGlobalCode):
     22
    1232016-10-20  Keith Miller  <keith_miller@apple.com>
    224
  • trunk/Source/JavaScriptCore/runtime/CodeCache.cpp

    r207618 r207684  
    183183    // This function assumes an input string that would result in a single function declaration.
    184184    StatementNode* statement = program->singleStatement();
    185     ASSERT(statement);
     185    if (UNLIKELY(!statement)) {
     186        JSToken token;
     187        error = ParserError(ParserError::SyntaxError, ParserError::SyntaxErrorIrrecoverable, token, "Parser error", -1);
     188        return nullptr;
     189    }
    186190    ASSERT(statement->isBlock());
    187     if (!statement || !statement->isBlock())
    188         return nullptr;
    189191
    190192    StatementNode* funcDecl = static_cast<BlockNode*>(statement)->singleStatement();
    191     ASSERT(funcDecl);
     193    if (UNLIKELY(!funcDecl)) {
     194        JSToken token;
     195        error = ParserError(ParserError::SyntaxError, ParserError::SyntaxErrorIrrecoverable, token, "Parser error", -1);
     196        return nullptr;
     197    }
    192198    ASSERT(funcDecl->isFuncDeclNode());
    193     if (!funcDecl || !funcDecl->isFuncDeclNode())
    194         return nullptr;
    195199
    196200    FunctionMetadataNode* metadata = static_cast<FuncDeclNode*>(funcDecl)->metadata();
Note: See TracChangeset for help on using the changeset viewer.