Skip to content

new Function(s) can be broken with regexps #165

Description

@robotlolita

So, I just noticed old v8's didn't follow the new Function specs and decided to review my Higgs' patch, and discovered you can break it with:

new Function("/{{/; }; x = 'evil'; /}/; function(){"); 

This should create a global x variable because the code counts the brackets inside regexps for balancing. Well, it should do that, but I just get an endless stream of GC instead:

$ ./higgs
Entering read-eval-print loop
To exit, press Ctrl+D (end-of-file) or type "exit" at the prompt
h> new Function("/{{/}; var x = 1; /}/; function(){")()
entering gcCollect
leaving gcCollect
entering gcCollect
leaving gcCollect
entering gcCollect
leaving gcCollect
entering gcCollect
leaving gcCollect
entering gcCollect
leaving gcCollect
^C

Anyway, fixing this is not quite trivial with the counting-brackets approach because / might be either a division operator or the start of a regexp inside an expression, depending on whether there's another slash on the same expression/line. I should have a patch for this by the weekend.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions