fuzzing: allow setup function to be called (#3175)
This allows to fuzzing of more interesting targets that require setup. Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
parent
59e74eb15d
commit
62451fd3eb
7 changed files with 21 additions and 6 deletions
2
plugin/cache/fuzz.go
vendored
2
plugin/cache/fuzz.go
vendored
|
@ -8,5 +8,5 @@ import (
|
||||||
|
|
||||||
// Fuzz fuzzes cache.
|
// Fuzz fuzzes cache.
|
||||||
func Fuzz(data []byte) int {
|
func Fuzz(data []byte) int {
|
||||||
return fuzz.Do(New(), data)
|
return fuzz.Do(New(), nil, data)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,5 +9,5 @@ import (
|
||||||
// Fuzz fuzzes cache.
|
// Fuzz fuzzes cache.
|
||||||
func Fuzz(data []byte) int {
|
func Fuzz(data []byte) int {
|
||||||
c := Chaos{}
|
c := Chaos{}
|
||||||
return fuzz.Do(c, data)
|
return fuzz.Do(c, nil, data)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ func Fuzz(data []byte) int {
|
||||||
zone, _ := Parse(strings.NewReader(fuzzMiekNL), name, "stdin", 0)
|
zone, _ := Parse(strings.NewReader(fuzzMiekNL), name, "stdin", 0)
|
||||||
f := File{Next: test.ErrorHandler(), Zones: Zones{Z: map[string]*Zone{name: zone}, Names: []string{name}}}
|
f := File{Next: test.ErrorHandler(), Zones: Zones{Z: map[string]*Zone{name: zone}, Names: []string{name}}}
|
||||||
|
|
||||||
return fuzz.Do(f, data)
|
return fuzz.Do(f, nil, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
const fuzzMiekNL = `
|
const fuzzMiekNL = `
|
||||||
|
|
|
@ -11,7 +11,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Do will fuzz p - used by gofuzz. See Makefile.fuzz for comments and context.
|
// Do will fuzz p - used by gofuzz. See Makefile.fuzz for comments and context.
|
||||||
func Do(p plugin.Handler, data []byte) int {
|
func Do(p plugin.Handler, fn SetupFunc, data []byte) int {
|
||||||
|
if fn != nil {
|
||||||
|
if err := fn(); err != nil {
|
||||||
|
panic("fuzz: " + err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
ctx := context.TODO()
|
ctx := context.TODO()
|
||||||
r := new(dns.Msg)
|
r := new(dns.Msg)
|
||||||
if err := r.Unpack(data); err != nil {
|
if err := r.Unpack(data); err != nil {
|
||||||
|
|
10
plugin/pkg/fuzz/setup.go
Normal file
10
plugin/pkg/fuzz/setup.go
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
package fuzz
|
||||||
|
|
||||||
|
// SetupFunc can be given to Do to perform a one time setup of the fuzzing
|
||||||
|
// environment. This function is called on every fuzz, it is your
|
||||||
|
// responsibility to make it idempotent. If SetupFunc returns an error, panic
|
||||||
|
// is called with that error.
|
||||||
|
//
|
||||||
|
// There isn't a ShutdownFunc, because fuzzing is supposed to be run for a long
|
||||||
|
// time and there isn't any hook to call it from.
|
||||||
|
type SetupFunc func() error
|
|
@ -17,5 +17,5 @@ func Fuzz(data []byte) int {
|
||||||
}
|
}
|
||||||
r := Rewrite{Rules: rules}
|
r := Rewrite{Rules: rules}
|
||||||
|
|
||||||
return fuzz.Do(r, data)
|
return fuzz.Do(r, nil, data)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,5 +9,5 @@ import (
|
||||||
// Fuzz fuzzes cache.
|
// Fuzz fuzzes cache.
|
||||||
func Fuzz(data []byte) int {
|
func Fuzz(data []byte) int {
|
||||||
w := Whoami{}
|
w := Whoami{}
|
||||||
return fuzz.Do(w, data)
|
return fuzz.Do(w, nil, data)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue