Skip to content

Commit

Permalink
Fix hang in lexer if file ends in a comment without a newline (#184)
Browse files Browse the repository at this point in the history
Found by fuzzer!
  • Loading branch information
asmaloney committed Jun 9, 2022
1 parent 2acde1d commit 67ce086
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion amod/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,14 @@ func lexSpace(l *lexer_amod) stateFn {
func lexComment(l *lexer_amod) stateFn {
l.pos += len(commentDelim)
i := strings.Index(l.input[l.pos:], "\n")
l.pos += i

// If we are at the end of file there may not be a newline,
// so take the rest of the input.
if i == -1 {
l.pos = len(l.input)
} else {
l.pos += i
}

l.emit(lexemeComment)

Expand Down

0 comments on commit 67ce086

Please sign in to comment.