coredns/plugin/pkg/fuzz/do.go
Miek Gieben 4276d29b81 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.
2017-09-29 22:28:13 +01:00

25 lines
487 B
Go

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
}