Skip to content

Commit f74773f

Browse files
committed
[CVE-2017-0223] Fix right paren location calculation for lambda with assignment expression
We don't calculate correct right paren location when a lambda contains an assignment expression where the assignment rhs is wrapped in parens. Due to the incorrect offset, we overwrite the buffer allocated in ScriptFunction::EnsureSourceString when we try to toString the lambda.
1 parent 1ae7e3c commit f74773f

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

lib/Parser/Parse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8440,7 +8440,7 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
84408440
{
84418441
// Parse the operand, make a new node, and look for more
84428442
IdentToken token;
8443-
pnodeT = ParseExpr<buildAST>(opl, NULL, fAllowIn, FALSE, pNameHint, &hintLength, &hintOffset, &token);
8443+
pnodeT = ParseExpr<buildAST>(opl, NULL, fAllowIn, FALSE, pNameHint, &hintLength, &hintOffset, &token, false, nullptr, plastRParen);
84448444

84458445
// Detect nested function escapes of the pattern "o.f = function(){...}" or "o[s] = function(){...}".
84468446
// Doing so in the parser allows us to disable stack-nested-functions in common cases where an escape

test/es6/lambda1.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,29 @@ var tests = [
477477
var l = async() => (async() => ('str'));
478478
assert.areEqual("async() => (async() => ('str'))", '' + l, "Nested async lambda should be correct");
479479
}
480+
},
481+
{
482+
name: "Lambda consisting of assignment expression should have correct source string",
483+
body: function () {
484+
var l = () => a = (123)
485+
assert.areEqual('() => a = (123)', '' + l, "Lambda to string should include the parens wrapping the return expression");
486+
487+
var l = () => a = (('๏บบ'))
488+
assert.areEqual("() => a = (('๏บบ'))", '' + l, "Multi-byte characters should not break the string");
489+
490+
var s = "() => a = ('\u{20ac}')";
491+
var l = eval(s);
492+
assert.areEqual(s, '' + l, "Unicode byte sequences should not break the string");
493+
494+
var l = async() => a = ({});
495+
assert.areEqual('async() => a = ({})', '' + l, "Async lambda should also be correct");
496+
497+
var l = () => a = (() => b = (123))
498+
assert.areEqual('() => a = (() => b = (123))', '' + l, "Nested lambda to string should be correct");
499+
500+
var l = async() => a = (async() => b = ('str'));
501+
assert.areEqual("async() => a = (async() => b = ('str'))", '' + l, "Nested async lambda should be correct");
502+
}
480503
}
481504
];
482505

0 commit comments

Comments
 (0)