...

Source file src/pkg/encoding/json/fuzz.go

     1	// Copyright 2019 The Go Authors. All rights reserved.
     2	// Use of this source code is governed by a BSD-style
     3	// license that can be found in the LICENSE file.
     4	
     5	// +build gofuzz
     6	
     7	package json
     8	
     9	import (
    10		"fmt"
    11	)
    12	
    13	func Fuzz(data []byte) (score int) {
    14		for _, ctor := range []func() interface{}{
    15			func() interface{} { return new(interface{}) },
    16			func() interface{} { return new(map[string]interface{}) },
    17			func() interface{} { return new([]interface{}) },
    18		} {
    19			v := ctor()
    20			err := Unmarshal(data, v)
    21			if err != nil {
    22				continue
    23			}
    24			score = 1
    25	
    26			m, err := Marshal(v)
    27			if err != nil {
    28				fmt.Printf("v=%#v\n", v)
    29				panic(err)
    30			}
    31	
    32			u := ctor()
    33			err = Unmarshal(m, u)
    34			if err != nil {
    35				fmt.Printf("v=%#v\n", v)
    36				fmt.Printf("m=%s\n", m)
    37				panic(err)
    38			}
    39		}
    40	
    41		return
    42	}
    43	

View as plain text