Skip to content

Commit

Permalink
language/parser: Fix infinite loop on unexpected character
Browse files Browse the repository at this point in the history
Ensure errors returned by the lexer are returned by any().

Hang found by go-fuzz.

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
  • Loading branch information
titanous committed Jul 18, 2016
1 parent 491504a commit a8b0417
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion language/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,7 @@ func any(parser *Parser, openKind int, parseFn parseFn, closeKind int) ([]interf
var nodes []interface{}
_, err := expect(parser, openKind)
if err != nil {
return nodes, nil
return nodes, err
}
for {
if skp, err := skip(parser, closeKind); err != nil {
Expand Down
10 changes: 10 additions & 0 deletions language/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,16 @@ func TestParseCreatesAst(t *testing.T) {

}

func TestParseUnexpectedCharacter(t *testing.T) {
_, err := Parse(ParseParams{Source: "{t(d:[[~"})
expectedError := &gqlerrors.Error{
Message: "Syntax Error GraphQL (1:8) Unexpected character \"~\".\n\n1: {t(d:[[~\n ^\n",
Positions: []int{7},
Locations: []location.SourceLocation{{1, 8}},
}
checkError(t, err, expectedError)
}

type errorMessageTest struct {
source interface{}
expectedMessage string
Expand Down

0 comments on commit a8b0417

Please sign in to comment.