Re: [nodejs] v0.11.1: (Function()).toString adds /**/ to argument list

80 views
Skip to first unread message

Ben Noordhuis

unread,
May 5, 2013, 5:32:52 AM5/5/13
to nod...@googlegroups.com
On Sun, May 5, 2013 at 9:04 AM, Andrew Petersen <senof...@gmail.com> wrote:
> If I do in REPL:
>
> ````
>> f = Function('a', 'b', 'c', 'd', 'e', "console.log('what what')")
> [Function]
>> f.toString()
> 'function anonymous(a,b,c,d,e\n/**/) {\nconsole.log(\'what what\')\n}'
> ````
>
> Notice how the function arguments have an extra /**/ in them? Not sure where
> this is coming from, but it broke a few (admittedly fragile) tests of mine.
> Is this change going to stick for sure in 0.11, or only temporary? Is there
> anymore info as to why this is happening?
>
> This happens in the REPL or in plain code, and does not occur in 0.6, 0.8,
> or 0.10.

It's because of [1] and [2]. It's hardening against arbitrary code
execution from inside the Function constructor:

$ v0.10/node -e 'Function("", "});console.log(\"OWNED\");(function(){")'
OWNED

$ master/node -e 'Function("", "});console.log(\"OWNED\");(function(){")'
undefined:4
})
^
SyntaxError: Parse error
at Function (<anonymous>)


I'm not sure if the change in the toString() output should be
considered a regression; I believe the spec only mandates that the
result can be evaluated with eval(). Please open a V8 issue if you
feel strongly about it. :-)

[1] https://code.google.com/p/v8/issues/detail?id=2470
[2] https://github.com/v8/v8/blob/762ba9c/src/v8natives.js#L1707-1713

Andrew Petersen

unread,
May 20, 2013, 11:32:49 PM5/20/13
to nod...@googlegroups.com
Ben, thank you so much for replying, and I'm sorry it took so long. Your explanation was very helpful!
Reply all
Reply to author
Forward
0 new messages