Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go-fuzz fixes #224

Merged
merged 2 commits into from
Aug 5, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix nil panic in UniqueOperationNamesRule with two anonymous operations
node.Name is nil when the operation is anonymous. Use the parent AST
node instead in this case.

Found with go-fuzz.

Commit: titanous/graphql@ab875bc
  • Loading branch information
chris-ramon committed Aug 5, 2017
commit a2900f88b4cf1034851aeedfa987a6191a83426b
10 changes: 7 additions & 3 deletions rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ func UniqueInputFieldNamesRule(context *ValidationContext) *ValidationRuleInstan
//
// A GraphQL document is only valid if all defined operations have unique names.
func UniqueOperationNamesRule(context *ValidationContext) *ValidationRuleInstance {
knownOperationNames := map[string]*ast.Name{}
knownOperationNames := make(map[string]ast.Node)

visitorOpts := &visitor.VisitorOptions{
KindFuncMap: map[string]visitor.NamedVisitFuncs{
Expand All @@ -1528,14 +1528,18 @@ func UniqueOperationNamesRule(context *ValidationContext) *ValidationRuleInstanc
if node.Name != nil {
operationName = node.Name.Value
}
var errNode ast.Node = node
if node.Name != nil {
errNode = node.Name
}
if nameAST, ok := knownOperationNames[operationName]; ok {
reportError(
context,
fmt.Sprintf(`There can only be one operation named "%v".`, operationName),
[]ast.Node{nameAST, node.Name},
[]ast.Node{nameAST, errNode},
)
} else {
knownOperationNames[operationName] = node.Name
knownOperationNames[operationName] = errNode
}
}
return visitor.ActionSkip, nil
Expand Down
6 changes: 6 additions & 0 deletions rules_unique_operation_names_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ func TestValidate_UniqueOperationNames_MultipleOperationsOfSameNameOfDifferentTy
testutil.RuleError(`There can only be one operation named "Foo".`, 2, 13, 5, 20),
})
}

func TestValidate_UniqueOperationNames_MultipleAnonymousOperations(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.UniqueOperationNamesRule, `{a}{b}`, []gqlerrors.FormattedError{
testutil.RuleError(`There can only be one operation named "".`, 1, 1, 1, 4),
})
}