mirror of
https://github.com/coredns/coredns.git
synced 2025-11-17 17:32:18 -05:00
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:
25
plugin/pkg/fuzz/do.go
Normal file
25
plugin/pkg/fuzz/do.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user