github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/parser/fuzz/fuzz.go (about)

     1  // Copyright 2019 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  // +build gofuzz
    12  
    13  // The parser fuzzer needs to live in its own package because it must import
    14  // the builtins package so functions that are hard coded in sql.y (like
    15  // "current_user") can be resolved. However importing that in parser creates a
    16  // cyclic dependency.
    17  
    18  package fuzz
    19  
    20  import (
    21  	"github.com/cockroachdb/cockroach/pkg/sql/parser"
    22  	// See above comment about why this is imported.
    23  	_ "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins"
    24  )
    25  
    26  func FuzzParse(data []byte) int {
    27  	_, err := parser.Parse(string(data))
    28  	if err != nil {
    29  		return 0
    30  	}
    31  	return 1
    32  }