Skip to content

Commit

Permalink
all: support cmd/go 1.18 fuzzing
Browse files Browse the repository at this point in the history
  • Loading branch information
thepudds committed Dec 16, 2021
1 parent e9f6624 commit 1c377fb
Show file tree
Hide file tree
Showing 82 changed files with 11,475 additions and 890 deletions.
232 changes: 134 additions & 98 deletions README.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions cmd/fzgen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## cmd/fzgen

See the project [README](https://github.com/thepudds/fzgo/) for more details.
11 changes: 11 additions & 0 deletions cmd/fzgen/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"os"

gen "github.com/thepudds/fzgen/gen"
)

func main() {
os.Exit(gen.FzgenMain())
}
44 changes: 44 additions & 0 deletions examples/inputs/arg-reuse/argreuse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Package argexample shows an example that would take longer to
// to panic simply using dvyukov/go-fuzz or 'go test -fuzz=.',
// but which should panic in 20-30 sec or so via fz.Chain
// when fz.Chain is properly reusing input arg values from a step
// as candidate input values to another step (currently
// just a few seconds with GODEBUG=fuzzseed=1, vs. 2-3 minutes for
// cmd/go fuzzing without arg reuse).
//
// To panic, this example has three requirements:
// 1. Step1 must be called.
// 2. Step2 must be subsequently called.
// 3. The two args passed to Step2 must match the first arg of Step1.
//
// fz.Chain usually solves this by wiring the one of the args to Step1 to the inputs to Step2.
//
// The intent is that this example is run sequentially (that is, not with concurrent steps).
//
// (go-fuzz and cmd/go fuzzing can solve this many ways, including by copying
// bytes, or picking same interesting values in the right spots, etc.).
package argexample

type PanicOnArgReuse struct {
rememberedInt int64
passedStep1 bool
}

func New(i int) *PanicOnArgReuse {
return &PanicOnArgReuse{}
}

func (p *PanicOnArgReuse) Step1(a, b int64) {
// zero value is too easy, as are repeating values.
if a != b && a != 0 && b != 0 {
p.rememberedInt = a
p.passedStep1 = true
}
}

func (p *PanicOnArgReuse) Step2(a, b int64) {
// TODO: fuzzer should reuse args beyond first arg, and then change this to b == p.rememberedB
if a == p.rememberedInt && b == p.rememberedInt && p.passedStep1 {
panic("bingo - found our desired panic")
}
}
15 changes: 15 additions & 0 deletions examples/inputs/race-xsync-map/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module github.com/thepudds/fzgen/examples/inputs/race-xsync-map

go 1.17

require (
github.com/puzpuzpuz/xsync v1.0.1-0.20210823092703-32778049b5f5
github.com/thepudds/fzgen v0.0.0-00010101000000-000000000000
)

require (
github.com/google/gofuzz v1.2.0 // indirect
github.com/sanity-io/litter v1.5.1 // indirect
)

replace github.com/thepudds/fzgen => ./../../..
49 changes: 49 additions & 0 deletions examples/inputs/race-xsync-map/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0 h1:GD+A8+e+wFkqje55/2fOVnZPkoDIu1VooBWfNrnY8Uo=
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/puzpuzpuz/xsync v0.0.0-20210815074145-06f072a152a8 h1:bAvbvlslJkn5r/JnGkDOoZ5/N1I6zBiDBcCpsZ8an/Q=
github.com/puzpuzpuz/xsync v0.0.0-20210815074145-06f072a152a8/go.mod h1:GF6mnc4fZ1Vit0eWBHPcthv2l1nE81+iZvLsexB/HM4=
github.com/puzpuzpuz/xsync v1.0.1-0.20210823092703-32778049b5f5 h1:ZoUoiy+1+jwi9B2+5F0Mh4HMlI/q01Nqt+qN9T2h5lA=
github.com/puzpuzpuz/xsync v1.0.1-0.20210823092703-32778049b5f5/go.mod h1:GF6mnc4fZ1Vit0eWBHPcthv2l1nE81+iZvLsexB/HM4=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/sanity-io/litter v1.5.1 h1:dwnrSypP6q56o3lFxTU+t2fwQ9A+U5qrXVO4Qg9KwVU=
github.com/sanity-io/litter v1.5.1/go.mod h1:5Z71SvaYy5kcGtyglXOC9rrUi3c1E8CamFWjQsazTh0=
github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312 h1:UsFdQ3ZmlzS0BqZYGxvYaXvFGUbCmPGy8DM7qWJJiIQ=
github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/thepudds/fzgo v0.2.3-0.20211028225222-cdf4f1cc8ee2/go.mod h1:ZgigL1toyKrar3rWdXz7Fuv7bUpKZ4BAYN49TpEFMCI=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
52 changes: 52 additions & 0 deletions examples/inputs/race-xsync-map/xsyncmap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// xsyncmap is a thin wrapper over github.com/puzpuzpuz/xsync.Map.

package xsyncmap

import "github.com/puzpuzpuz/xsync"

// target https://github.com/puzpuzpuz/xsync at 32778049b

type XSyncMap struct {
xsyncmap *xsync.Map
}

func NewXSyncMap() *XSyncMap {
return &XSyncMap{xsync.NewMap()}
}

func (m *XSyncMap) Delete(key string) {
m.xsyncmap.Delete(key)
}

func (m *XSyncMap) Load(key string) (value int8, ok bool) {
v, ok := m.xsyncmap.Load(key)
if !ok {
return 0, false
}
return v.(int8), ok
}

func (m *XSyncMap) LoadAndDelete(key string) (value int8, loaded bool) {
v, loaded := m.xsyncmap.LoadAndDelete(key)
if !loaded {
return 0, false
}
return v.(int8), loaded
}

func (m *XSyncMap) LoadOrStore(key string, value int8) (actual int8, loaded bool) {
v, loaded := m.xsyncmap.LoadOrStore(key, value)
if !loaded {
return 0, false
}
return v.(int8), loaded
}

func (m *XSyncMap) Store(key string, value int8) {
m.xsyncmap.Store(key, value)
}

// Range will be ignored by default by fzgen.
func (m *XSyncMap) Range(f func(key string, value interface{}) bool) {
m.xsyncmap.Range(f)
}
15 changes: 15 additions & 0 deletions examples/inputs/race-xsync-mpmcqueue/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module github.com/thepudds/fzgen/examples/inputs/race-xsyncmap

go 1.17

require (
github.com/puzpuzpuz/xsync v1.0.1-0.20210823092703-32778049b5f5
github.com/thepudds/fzgen v0.0.0-00010101000000-000000000000
)

require (
github.com/google/gofuzz v1.2.0 // indirect
github.com/sanity-io/litter v1.5.1 // indirect
)

replace github.com/thepudds/fzgen => ./../../..
49 changes: 49 additions & 0 deletions examples/inputs/race-xsync-mpmcqueue/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0 h1:GD+A8+e+wFkqje55/2fOVnZPkoDIu1VooBWfNrnY8Uo=
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/puzpuzpuz/xsync v0.0.0-20210815074145-06f072a152a8 h1:bAvbvlslJkn5r/JnGkDOoZ5/N1I6zBiDBcCpsZ8an/Q=
github.com/puzpuzpuz/xsync v0.0.0-20210815074145-06f072a152a8/go.mod h1:GF6mnc4fZ1Vit0eWBHPcthv2l1nE81+iZvLsexB/HM4=
github.com/puzpuzpuz/xsync v1.0.1-0.20210823092703-32778049b5f5 h1:ZoUoiy+1+jwi9B2+5F0Mh4HMlI/q01Nqt+qN9T2h5lA=
github.com/puzpuzpuz/xsync v1.0.1-0.20210823092703-32778049b5f5/go.mod h1:GF6mnc4fZ1Vit0eWBHPcthv2l1nE81+iZvLsexB/HM4=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/sanity-io/litter v1.5.1 h1:dwnrSypP6q56o3lFxTU+t2fwQ9A+U5qrXVO4Qg9KwVU=
github.com/sanity-io/litter v1.5.1/go.mod h1:5Z71SvaYy5kcGtyglXOC9rrUi3c1E8CamFWjQsazTh0=
github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312 h1:UsFdQ3ZmlzS0BqZYGxvYaXvFGUbCmPGy8DM7qWJJiIQ=
github.com/stretchr/testify v0.0.0-20161117074351-18a02ba4a312/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/thepudds/fzgo v0.2.3-0.20211028225222-cdf4f1cc8ee2/go.mod h1:ZgigL1toyKrar3rWdXz7Fuv7bUpKZ4BAYN49TpEFMCI=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
33 changes: 33 additions & 0 deletions examples/inputs/race-xsync-mpmcqueue/xsyncqueue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// xsyncqueue is a thin wrapper over github.com/puzpuzpuz/xsync.MPMCQueue.

package xsyncqueue

import "github.com/puzpuzpuz/xsync"

type XSyncMPMCQueue struct {
xsyncq *xsync.MPMCQueue
}

func NewMPMCQueue(capacity int) *XSyncMPMCQueue {
return &XSyncMPMCQueue{xsync.NewMPMCQueue(capacity)}
}

func (q *XSyncMPMCQueue) Dequeue() int8 {
return q.xsyncq.Dequeue().(int8)
}

func (q *XSyncMPMCQueue) Enqueue(item int8) {
q.xsyncq.Enqueue(item)
}

func (q *XSyncMPMCQueue) TryDequeue() (item int8, ok bool) {
v, ok := q.xsyncq.TryDequeue()
if !ok {
return 0, false
}
return v.(int8), true
}

func (q *XSyncMPMCQueue) TryEnqueue(item int8) bool {
return q.xsyncq.TryEnqueue(item)
}
46 changes: 46 additions & 0 deletions examples/inputs/race/race.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// raceexample wraps sync.Map in a type-safe way, but sadly the implementation has a
// a possible data race in handling a counter on the objects stored in the sync.Map.
//
// To observe the data race with the race detector:
// 1. A Store must be followed by two Loads, and all three must use the same key.
// 2. The Store must have certain payload data (Answer: 42).
// 3. The two Loads must happen concurrently.
// 4. Prior to the two Loads, no other Store can update the key to have a non-matching payload.
//
// Using the fzgen/fuzzer.Chain created by default via 'fzgen -chain -parallel -pkg=github.com/thepudds/fzgen/examples/inputs/race',
// this data race is typically caught after a few minutes of fuzzing with '-race' when starting from scratch.
package raceexample

import (
"sync"
)

type MySafeMap struct {
syncMap sync.Map
}

func NewMySafeMap() *MySafeMap {
return &MySafeMap{}
}

func (m *MySafeMap) Store(key [16]byte, req *Request) {
m.syncMap.Store(key, req)
}

func (m *MySafeMap) Load(key [16]byte) *Request {
r, ok := m.syncMap.Load(key)
if ok {
req := r.(*Request)
if req.Answer == 42 {
// DATA RACE (but requires: matching store/load keys, and concurrent matching load keys, and certain payload data)
req.deepQuestion++
}
return req
}
return nil
}

type Request struct {
Answer int8 // TODO: change to int when cmd/go has the equivalent of go-fuzz sonar or libfuzzer comparision instrumentation
deepQuestion int
}
47 changes: 47 additions & 0 deletions examples/inputs/return-reuse/returnreuse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Package returnexample shows an example that would be quite
// challenging to panic simply using dvyukov/go-fuzz or 'go test -fuzz=.',
// but which should panic almost immediately via fz.Chain
// when fz.Chain is properly wiring the return values from a step
// as candidate input values to another step.
//
// To panic, this example has three requirements:
// 1. Step1 must be called, where Step1 returns the sha256 of its input uint64.
// 2. Step2 must be subsequently called.
// 3. The sha256 of the uint64 passed to the most recent Step1 must equal the [32]byte passed to Step2.
//
// fz.Chain solves this by wiring the output of Step1 to the input to Step2.
//
// The intent is that this example is run sequentially (that is, not with concurrent steps).
//
// (go-fuzz's sonar won't look at a [32]byte sha256, and
// neither will the current value comparision instrumentation in 'go test -fuzz=.',
// and there are no magic literals to automatically learn for a dictionary).
package returnexample

import (
"crypto/sha256"
"encoding/binary"
)

type PanicOnReturnReuse struct {
rememberedSha [32]byte
calledStep1 bool
}

func New(i int) *PanicOnReturnReuse {
return &PanicOnReturnReuse{}
}

func (p *PanicOnReturnReuse) Step1(input uint64) [32]byte {
b := make([]byte, 8)
binary.LittleEndian.PutUint64(b, input)
p.rememberedSha = sha256.Sum256(b)
p.calledStep1 = true
return p.rememberedSha
}

func (p *PanicOnReturnReuse) Step2(inputSha [32]byte) {
if inputSha == p.rememberedSha && p.calledStep1 {
panic("bingo - found our desired panic")
}
}
Loading

0 comments on commit 1c377fb

Please sign in to comment.