aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugin/cache/fuzz.go2
-rw-r--r--plugin/chaos/fuzz.go2
-rw-r--r--plugin/file/fuzz.go2
-rw-r--r--plugin/pkg/fuzz/do.go7
-rw-r--r--plugin/pkg/fuzz/setup.go10
-rw-r--r--plugin/rewrite/fuzz.go2
-rw-r--r--plugin/whoami/fuzz.go2
7 files changed, 21 insertions, 6 deletions
diff --git a/plugin/cache/fuzz.go b/plugin/cache/fuzz.go
index 9bf6cb3a9..401e9b166 100644
--- a/plugin/cache/fuzz.go
+++ b/plugin/cache/fuzz.go
@@ -8,5 +8,5 @@ import (
// Fuzz fuzzes cache.
func Fuzz(data []byte) int {
- return fuzz.Do(New(), data)
+ return fuzz.Do(New(), nil, data)
}
diff --git a/plugin/chaos/fuzz.go b/plugin/chaos/fuzz.go
index f0e23b083..f5a79f775 100644
--- a/plugin/chaos/fuzz.go
+++ b/plugin/chaos/fuzz.go
@@ -9,5 +9,5 @@ import (
// Fuzz fuzzes cache.
func Fuzz(data []byte) int {
c := Chaos{}
- return fuzz.Do(c, data)
+ return fuzz.Do(c, nil, data)
}
diff --git a/plugin/file/fuzz.go b/plugin/file/fuzz.go
index 84f5c1853..535db0e93 100644
--- a/plugin/file/fuzz.go
+++ b/plugin/file/fuzz.go
@@ -15,7 +15,7 @@ func Fuzz(data []byte) int {
zone, _ := Parse(strings.NewReader(fuzzMiekNL), name, "stdin", 0)
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 = `
diff --git a/plugin/pkg/fuzz/do.go b/plugin/pkg/fuzz/do.go
index 054c4298a..95a5400f1 100644
--- a/plugin/pkg/fuzz/do.go
+++ b/plugin/pkg/fuzz/do.go
@@ -11,7 +11,12 @@ import (
)
// 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()
r := new(dns.Msg)
if err := r.Unpack(data); err != nil {
diff --git a/plugin/pkg/fuzz/setup.go b/plugin/pkg/fuzz/setup.go
new file mode 100644
index 000000000..7c44b0ef3
--- /dev/null
+++ b/plugin/pkg/fuzz/setup.go
@@ -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
diff --git a/plugin/rewrite/fuzz.go b/plugin/rewrite/fuzz.go
index 043a4a5c9..545ef5b93 100644
--- a/plugin/rewrite/fuzz.go
+++ b/plugin/rewrite/fuzz.go
@@ -17,5 +17,5 @@ func Fuzz(data []byte) int {
}
r := Rewrite{Rules: rules}
- return fuzz.Do(r, data)
+ return fuzz.Do(r, nil, data)
}
diff --git a/plugin/whoami/fuzz.go b/plugin/whoami/fuzz.go
index d9bbcee2b..917a9189f 100644
--- a/plugin/whoami/fuzz.go
+++ b/plugin/whoami/fuzz.go
@@ -9,5 +9,5 @@ import (
// Fuzz fuzzes cache.
func Fuzz(data []byte) int {
w := Whoami{}
- return fuzz.Do(w, data)
+ return fuzz.Do(w, nil, data)
}