Skip to content

Commit

Permalink
Check for invalid NonNull in isValidLiteralValue
Browse files Browse the repository at this point in the history
Nil panic found with go-fuzz.

Signed-off-by: Jonathan Rudenberg <[email protected]>
  • Loading branch information
titanous authored and chris-ramon committed Aug 5, 2017
1 parent d114382 commit 5773286
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,9 @@ func VariablesInAllowedPositionRule(context *ValidationContext) *ValidationRuleI
func isValidLiteralValue(ttype Input, valueAST ast.Value) (bool, []string) {
// A value must be provided if the type is non-null.
if ttype, ok := ttype.(*NonNull); ok {
if e := ttype.Error(); e != nil {
return false, []string{e.Error()}
}
if valueAST == nil {
if ttype.OfType.Name() != "" {
return false, []string{fmt.Sprintf(`Expected "%v!", found null.`, ttype.OfType.Name())}
Expand Down
4 changes: 4 additions & 0 deletions rules_default_values_of_correct_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@ func TestValidate_VariableDefaultValuesOfCorrectType_ListVariablesWithInvalidIte
2, 40),
})
}

func TestValidate_VariableDefaultValuesOfCorrectType_InvalidNonNull(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.DefaultValuesOfCorrectTypeRule, `query($g:e!){a}`)
}

0 comments on commit 5773286

Please sign in to comment.