Add fuzzing infrastructure (#1118)

Fix file/fuzz.go build and docs in Makefile.fuzz
Each plugin can add a fuzz.go to join the fuzzing craze.
pkg/fuzz/do.go could be made a lot smarter, but is probably good enough
for starters.

$ make -f Makefile.fuzz <plugin>

will build with go-fuzz-build and then execute a go-fuzz run. Each
plugin's fuzz run uses a per-plugin directory to store the fuzz data.
This commit is contained in:
Miek Gieben
2017-09-29 22:28:13 +01:00
committed by GitHub
parent 23526aec1d
commit 4276d29b81
6 changed files with 158 additions and 0 deletions

25
plugin/pkg/fuzz/do.go Normal file
View File

@@ -0,0 +1,25 @@
package fuzz
import (
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns"
"golang.org/x/net/context"
)
// Do will fuzz p - used by gofuzz. See Maefile.fuzz for comments and context.
func Do(p plugin.Handler, data []byte) int {
ctx := context.TODO()
ret := 1
r := new(dns.Msg)
if err := r.Unpack(data); err != nil {
ret = 0
}
if _, err := p.ServeDNS(ctx, &test.ResponseWriter{}, r); err != nil {
ret = 1
}
return ret
}