| 
									
										
										
										
											2018-02-23 15:02:05 +00:00
										 |  |  | // Package fuzz contains functions that enable fuzzing of plugins.
 | 
					
						
							| 
									
										
										
										
											2017-09-29 22:28:13 +01:00
										 |  |  | package fuzz
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							| 
									
										
										
										
											2018-04-22 08:34:35 +01:00
										 |  |  | 	"context"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-29 22:28:13 +01:00
										 |  |  | 	"github.com/coredns/coredns/plugin"
 | 
					
						
							|  |  |  | 	"github.com/coredns/coredns/plugin/test"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/miekg/dns"
 | 
					
						
							|  |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // 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
 | 
					
						
							|  |  |  | }
 |