Skip to content

Commit

Permalink
fix(parser): fixed issue with OctalEscapeSequence discovered by fuzzer
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed Jun 4, 2019
1 parent 84bd498 commit 5d62f79
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/lexer/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ export function parseEscape(parser: ParserState, context: Context, first: number
}
}

parser.flags |= Flags.Octals;

parser.index = index - 1;
parser.column = column - 1;
}
}

parser.flags |= Flags.Octals;

return code;
}

Expand Down
4 changes: 2 additions & 2 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2673,7 +2673,7 @@ export function parseFunctionBody(
Token.RightBrace
);

parser.flags &= ~Flags.SimpleParameterList;
parser.flags &= ~(Flags.SimpleParameterList | Flags.Octals);

if (parser.token === Token.Assign) report(parser, Errors.InvalidStatementStart);

Expand Down Expand Up @@ -5876,7 +5876,7 @@ function parseClassElementList(

const { token, tokenIndex } = parser;

if (token & Token.IsIdentifier) {
if (token & (Token.IsIdentifier | Token.FutureReserved)) {
key = parseIdentifier(parser, context, tokenIndex);

switch (token) {
Expand Down
2 changes: 1 addition & 1 deletion src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export const enum Token {
PrivateKeyword = 102 | FutureReserved,
ProtectedKeyword = 103 | FutureReserved,
PublicKeyword = 104 | FutureReserved,
StaticKeyword = 105 | FutureReserved | IsIdentifier,
StaticKeyword = 105 | FutureReserved,
YieldKeyword = 106 | FutureReserved | IsExpressionStart | IsIdentifier,

/* Contextual keywords */
Expand Down
19 changes: 19 additions & 0 deletions test/parser/declarations/async-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,20 @@ describe('Declarations - Async Function', () => {
'async function fib(n) { return (n == 0 || n == 1) ? n : await fib(n - 1) + await fib(n - 2); }',
'var hardcoreFib = async function fib2(n) { return (n == 0 || n == 1) ? n : await fib2(n - 1) + await fib2(n - 2); }',
'() => class extends (async function() {}) {}',
'async function f() { class x { foo(x=new (await)()){} } }',
'async function f() { class x extends await y { } }',
`async function yield() {}`,
'async function x () { a = { a: await(a) } }',
'async function* a(){}',
'async function f() { class x { await(){} } }',
'async function f() { class x { foo(x=await){} } }',
'function f() { class x { [await](){} } }',
'(async function* (){})',
'async function* a() { for (let m in ((yield))) x; (r = a) => {} }',
'async function f() { class x { foo(await){} } }',
'function f() { class x { await(){} } }',
'async function f() { class x extends feh(await y) { } }',
'function f() { class x { foo(x=new (await)()){} } }',
'function f() { return await; }',
`async function *gen() {
yield {
Expand Down Expand Up @@ -178,12 +187,22 @@ describe('Declarations - Async Function', () => {

for (const arg of [
'async function f() { var await = { await : async function foo() {} } }',
'async function f() { class x { foo(x=await y){} } }',
'async function f() { class x { foo(x=new (await y)()){} } }',
'async function f(async, await) { var x = await async; return x; }',
'async function f() { class x { foo(await y){} } }',
'function f() { class x { foo(x=await y){} } }',
'async function foo() { async function bar(a = await baz()) {} }',
'async function wrap() {\n({a = await b} = obj) => a\n}',
'function f() { class x { foo(x=new (await y)()){} } }',
'async function wrap() {\n(a = await b) => a\n}',
'async function f() { class x extends await { } }',
'function f() { class x { await y(){} } }',
'async function f() { class await { } }',
'function f() { class x { [await y](){} } }',
'async function * f() { for await ({0: a} = 1 of []); }',
'async function * f() { for await ({0: a = 1} = 1 of []); }',
'async function f() { class x extends feh(await) { } }',
'async function * f() { for await ({a: a} = 1 of []); }',
"async function f() { 'use strict'; for await ({a} = 1 of []); }",
'async function foo() { await }',
Expand Down
3 changes: 3 additions & 0 deletions test/parser/expressions/await.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ describe('Expressions - Await', () => {
['async function g(){class x {*f(foo = await bar){}} }', Context.None],
['async function af(a, b = await a) { }', Context.None],
['var o = { async\nam() { } };', Context.None],
['async function x({await}) { return 1 }', Context.None],
['async function f() { return {await}; }', Context.None],
['async function f() { return {await = 0} = {}; }', Context.None],
['async function g(){class x {async f(foo = await bar){}} }', Context.None],
['async function g(){class x {f(foo = await bar){}} }', Context.None],
['async function g(){let o = {async *f(foo = await bar){}} }', Context.None],
Expand Down
49 changes: 45 additions & 4 deletions test/parser/miscellaneous/early-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('Miscellaneous - Early errors', () => {
'({get a(){}} = 0)',
`({set a(b){}} = 0)`,
`({a(b){}} = 0)`,
'"use strict"; ({arguments = 1} = 2);',
`[0] = 0;`,
`0 = 0;`,
`({a}) = 0;`,
Expand All @@ -27,10 +28,13 @@ describe('Miscellaneous - Early errors', () => {
'[...new a] = 0;',
'for({a: 0} in 0);',
'for([0] in 0);',
'for(const let of 1);',
'for([0] of 0);',
'for(({a: 0}) in 0);',
'for(([0]) in 0);',
'for(({a: 0}) of 0);',
'!function a(b = super[1]){}',
'function *a() { (b = yield) => {} }',
'for(([0]) of 0);',
'for((0) of 0);',
'\\u0000',
Expand All @@ -52,6 +56,14 @@ describe('Miscellaneous - Early errors', () => {
'class l\\u{65}t {}',
'(class yield {})',
'({ a(){ super(); } });',
'"use strict"; ([yield] = a)',
'class a extends b { constructor() { !{*constructor() { super(); }}; } }',
'"use strict"; !function* arguments(){}',
'!function(a){ super.b }',
'class a extends b { static prototype(){} }',
'function a() {"use strict"; ({ set b(eval) { } }); }',
'!{ get a() { "use strict"; +let; } }',
'function a(){ "use strict"; function a(yield){}}',
'({ a(){ {{ if(0) (( super() )); }} } });',
'class A extends B { constructor() { !{constructor() { super(); }}; } }',
'class A extends B { constructor() { !{*constructor() { super(); }}; } }',
Expand All @@ -78,6 +90,8 @@ describe('Miscellaneous - Early errors', () => {
'!function(a = super.b){}',
'function f(a){ super.b }',
'!{ a() { !function(){ super.b(); } } };',
'for(const a = 1, let = 2;;);',
'var a = new.target;',
'class A extends B { a() { function f(){ super.b(); } } }',
'class A extends B { a() { !function(){ super.b(); } } }',
'function f(a = super()){}',
Expand Down Expand Up @@ -105,6 +119,8 @@ describe('Miscellaneous - Early errors', () => {
'function* g(){ !function*(a = x + f(yield)){} }',
'function* g(){ !function*([a = yield]){} }',
'!function* (a = super.b){}',
'function* a(){ !function*([b = yield]){} }',
'class a { b(eval){} };',
'!{ a() { !function* (a = super.b()){} } };',
'class A extends B { a() { function* f(a = super.b()){} } }',
'class A extends B { a() { !function* (a = super.b()){} } }',
Expand All @@ -122,7 +138,6 @@ describe('Miscellaneous - Early errors', () => {
"function a([]){'use strict';}",
'for(const a = 1;;) c: function b(){}',
'!{ a() { function* b(a = super.c()){} } };',
'({ a = 0 });',
'({a(b){}} = 0)',
'({a}) = 0;',
'class A { constructor(){} constructor(){} }',
Expand Down Expand Up @@ -204,18 +219,36 @@ describe('Miscellaneous - Early errors', () => {
"function a() { 'use strict'; let = 1; }",
' [...new a] = 0;',
` for(const a in b) d: function c(){}`,
'class a extends b { c() { function d(c = super.e()){} } }',
'"use strict"; (eval)=>1',
` /./ii`,
`(a, ...b)`,
' for(const a = 1, let = 2;;);',
` function a() { "use strict"; private = 1; }`,
'function a(static) { "use strict"; }',
'({ a(){ super(); } });',
'for(const a;;);',
`"use strict"; for (a in let) {}`,
'function* a(){ (b = yield* c) => 1; }',
'for({a: 0} of 0);',
'b: break a;',
'let a, let = 1;',
'class static {}',
'while(1) !function(){ break; };',
'function* a(){ (b = c + d(yield)) => 1; }',
'class a {set constructor(b){}}',
'if(1) c: b: function a(){}',
'while(1) !function(){ continue; };',
'function* a(b = super()){}',
'for(let a;;) c: function b(){}',
// 'let \\u0061, \\u{0061};',
'({ a(){ super(); } });',
'for(const a = 1, b;;);',
'for([0] of 0);',
'function* a(){ ({ *b(c = yield){} }); }',
"function a() {'use strict'; ({ b: 1, c(eval) { } }); }",
'"use strict"; arguments => 1',
'if(1) continue;',
'do b: function a(){} while (1);',
'function a() { "use strict"; var package; }',
'[a] *= 0;',
'let a, b, c, let;',
'"use strict"; +yield',
Expand All @@ -236,10 +269,14 @@ describe('Miscellaneous - Early errors', () => {
'!{ a() { !function* (a = super.b()){} } };',
'for(const a = 1;;) c: function b(){}',
'function* a(){ ({b = yield}) => 1; }',
'function* a(){ ({b = yield}) => 1; }',
'function* a(){ (b = yield c) => 1; }',
// 'class a {static [static](){};}',
'class a {static [static](){};}',
'function* a(){ function* b(c = yield){} }',
'function a(){ c: while(1) continue b; }',
"function a() {'use strict'; eval = 1; }",
'("\\u{FFFFFFF}")',
"function a() {'use strict'; function eval() { } }",
'for(const a;;);',
'/[a-z]/z',
`var af = x
Expand Down Expand Up @@ -275,6 +312,10 @@ describe('Miscellaneous - Early errors', () => {
'function* g(){ !function*([a = yield]){} }',
'function* g(){ !function*(...{a = yield}){} }',
'function* a(){ function* b({[yield]: c}){} }',
'function* a(){ ({ *b(c = d + e(yield)){} }); }',
'a: while (true) { (function () { break a; }); }',
'function a() { "use strict"; interface = 1; }',
'function a([yield]){ "use strict"; }',
'({set a(b){}} = 0)',
'"use strict"; var yield;',
'function* a(){ (b = yield c) => 1; }',
Expand Down
2 changes: 2 additions & 0 deletions test/parser/miscellaneous/failure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,8 @@ describe('Miscellaneous - Failure', () => {
'function f(foo = [{m: t(+await bar)}]){}',
'async function f(foo = [{m: t(+await bar)}]){}',
'async ([x] = await bar);',
'function *a({yield}){}',
'function *a({yield = 0}){}',
'(foo = +await bar) => {}',
'async (foo = +await bar) => {}',
'(foo = [{m: 5 + t(+await bar)}]) => {}',
Expand Down

0 comments on commit 5d62f79

Please sign in to comment.