mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-03 18:53:13 -05:00 
			
		
		
		
	plugin/forward: add fuzzing (#3188)
* plugin/forward: add fuzzing Add fuzz.go for forward Signed-off-by: Miek Gieben <miek@miek.nl> * Make it compile Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
		
							
								
								
									
										34
									
								
								plugin/forward/fuzz.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								plugin/forward/fuzz.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
// +build gofuzz
 | 
			
		||||
 | 
			
		||||
package forward
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/coredns/coredns/plugin/pkg/dnstest"
 | 
			
		||||
	"github.com/coredns/coredns/plugin/pkg/fuzz"
 | 
			
		||||
 | 
			
		||||
	"github.com/miekg/dns"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var f *Forward
 | 
			
		||||
 | 
			
		||||
// abuse init to setup a environment to test against. This start another server to that will
 | 
			
		||||
// reflect responses.
 | 
			
		||||
func init() {
 | 
			
		||||
	f = New()
 | 
			
		||||
	s := dnstest.NewServer(r{}.reflectHandler)
 | 
			
		||||
	f.proxies = append(f.proxies, NewProxy(s.Addr, "tcp"))
 | 
			
		||||
	f.proxies = append(f.proxies, NewProxy(s.Addr, "udp"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Fuzz fuzzes forward.
 | 
			
		||||
func Fuzz(data []byte) int {
 | 
			
		||||
	return fuzz.Do(f, nil, data)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type r struct{}
 | 
			
		||||
 | 
			
		||||
func (r r) reflectHandler(w dns.ResponseWriter, req *dns.Msg) {
 | 
			
		||||
	m := new(dns.Msg)
 | 
			
		||||
	m.SetReply(req)
 | 
			
		||||
	w.WriteMsg(m)
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user