Skip to content

Commit

Permalink
Fix infinity loop issue (#127)
Browse files Browse the repository at this point in the history
* Fix infinity loop issue

* fix linter issues
  • Loading branch information
loga4 authored Jun 3, 2022
1 parent 8aef856 commit 5aff77c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,13 @@ export class Parser {
}
}

if (this.matches('COLON')) {
return {
type: 'StringLiteral',
value: null
}
}

this.report(`Unknown token "${this.consume().type}"`)
}

Expand Down Expand Up @@ -507,8 +514,22 @@ export class Parser {

this.matches('TICK')

let loopDetectorCursor = 0
let loopDetector = false
while (!this.eof() && this.peek().type !== 'TICK') {
node.body.push(this.walk(node.body))
loopDetectorCursor++
if (loopDetectorCursor >= 10000) {
loopDetector = true
break
}
}

if (loopDetector) {
while (!this.eof() && this.peek().type !== 'TICK') {
this.cursor++
}
this.report('Infinite loop detected')
}

if (this.eof()) {
Expand Down
8 changes: 8 additions & 0 deletions test/examples/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,14 @@ const cases = [
source: "`a == 0x0 ? 'concat ' + a : 'else'`",
bindings: { a: address('0x0000000000000000000000000000000000000001') }
}, 'else'],
[{
source: "`a : 'concat ' + a : 'else'`",
bindings: { a: address('0x0000000000000000000000000000000000000001') }
}, '0x0000000000000000000000000000000000000001'],
[{
source: "`a == 0x0 : 'concat ' + a : 'else'`",
bindings: { a: address('0x0000000000000000000000000000000000000001') }
}, 'false concat 0x0000000000000000000000000000000000000001 else'],

// External calls
[{
Expand Down

0 comments on commit 5aff77c

Please sign in to comment.