mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 10:13:14 -04:00 
			
		
		
		
	fuzz: some cleanups (#3143)
* fuzz: some cleanups Signed-off-by: Miek Gieben <miek@miek.nl> * smaller Signed-off-by: Miek Gieben <miek@miek.nl> * documentation Signed-off-by: Miek Gieben <miek@miek.nl> * comments Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
		
							
								
								
									
										27
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								Makefile
									
									
									
									
									
								
							| @@ -47,22 +47,17 @@ endif | |||||||
| ifeq ($(TEST_TYPE),fuzzit) | ifeq ($(TEST_TYPE),fuzzit) | ||||||
| 	# skip fuzzing for PR | 	# skip fuzzing for PR | ||||||
| 	if [ "$(TRAVIS_PULL_REQUEST)" = "false" ] || [ "$(FUZZIT_TYPE)" = "local-regression" ] ; then \ | 	if [ "$(TRAVIS_PULL_REQUEST)" = "false" ] || [ "$(FUZZIT_TYPE)" = "local-regression" ] ; then \ | ||||||
|         export GO111MODULE=off; \ | 		export GO111MODULE=off; \ | ||||||
|         go get -u github.com/dvyukov/go-fuzz/go-fuzz-build; \ | 		go get -u github.com/dvyukov/go-fuzz/go-fuzz-build; \ | ||||||
|         go get -u -v .; \ | 		go get -u -v .; \ | ||||||
|         cd ../../go-acme/lego; \ | 		cd ../../go-acme/lego && git checkout v2.5.0; \ | ||||||
|         git checkout v2.5.0; \ | 		cd ../../coredns/coredns; \ | ||||||
|         cd ../../coredns/coredns; \ | 		LIBFUZZER=YES $(MAKE) -f Makefile.fuzz all; \ | ||||||
|         LIBFUZZER=YES make -f Makefile.fuzz cache chaos file rewrite whoami corefile; \ | 		$(MAKE) -sf Makefile.fuzz fuzzit; \ | ||||||
|         wget -O fuzzit https://github.com/fuzzitdev/fuzzit/releases/download/v2.4.27/fuzzit_Linux_x86_64; \ | 		for i in `$(MAKE) -sf Makefile.fuzz echo`; do echo $$i; \ | ||||||
|         chmod a+x fuzzit; \ | 			./fuzzit create job --type $(FUZZIT_TYPE) coredns/$$i ./$$i; \ | ||||||
|         ./fuzzit create job --type $(FUZZIT_TYPE) coredns/cache ./cache; \ | 		done; \ | ||||||
|         ./fuzzit create job --type $(FUZZIT_TYPE) coredns/chaos ./chaos; \ | 	fi; | ||||||
|         ./fuzzit create job --type $(FUZZIT_TYPE) coredns/file ./file; \ |  | ||||||
|         ./fuzzit create job --type $(FUZZIT_TYPE) coredns/rewrite ./rewrite; \ |  | ||||||
|         ./fuzzit create job --type $(FUZZIT_TYPE) coredns/whoami ./whoami; \ |  | ||||||
|         ./fuzzit create job --type $(FUZZIT_TYPE) coredns/corefile ./corefile; \ |  | ||||||
|     fi; |  | ||||||
| endif | endif | ||||||
|  |  | ||||||
| core/plugin/zplugin.go core/dnsserver/zdirectives.go: plugin.cfg | core/plugin/zplugin.go core/dnsserver/zdirectives.go: plugin.cfg | ||||||
|   | |||||||
| @@ -1,5 +1,7 @@ | |||||||
| # Makefile for fuzzing | # Makefile for fuzzing | ||||||
| # | # | ||||||
|  | # With https://app.fuzzit.dev/ we are continuously fuzzing CoreDNS. | ||||||
|  | # | ||||||
| # Use go-fuzz and needs the tools installed. For each fuzz.go in a plugin's directory | # Use go-fuzz and needs the tools installed. For each fuzz.go in a plugin's directory | ||||||
| # you can start the fuzzing with: make -f Makefile.fuzz <plugin> | # you can start the fuzzing with: make -f Makefile.fuzz <plugin> | ||||||
| # e.g. | # e.g. | ||||||
| @@ -9,11 +11,13 @@ | |||||||
| # Each plugin that wants to join the fuzzing fray only needs to add a fuzz.go that calls | # Each plugin that wants to join the fuzzing fray only needs to add a fuzz.go that calls | ||||||
| # the plugins's ServeDNS and used the plugin/pkg/fuzz for the Do function. | # the plugins's ServeDNS and used the plugin/pkg/fuzz for the Do function. | ||||||
| # | # | ||||||
| # Installing go-fuzz | # Installing go-fuzz is very tricky because it does not support Go modules, see the `Makefile` | ||||||
| #$ go get github.com/dvyukov/go-fuzz/go-fuzz | # for the current trickery. The following may do the trick: | ||||||
| #$ go get github.com/dvyukov/go-fuzz/go-fuzz-build | # | ||||||
|  | # GO111MODULE=off go get github.com/dvyukov/go-fuzz/go-fuzz-build | ||||||
|  |  | ||||||
| REPO:="github.com/coredns/coredns" | REPO:="github.com/coredns/coredns" | ||||||
|  | FUZZIT:=v2.4.28 | ||||||
| # set LIBFUZZER=YES to build libfuzzer compatible targets | # set LIBFUZZER=YES to build libfuzzer compatible targets | ||||||
|  |  | ||||||
| FUZZ:=$(dir $(wildcard plugin/*/fuzz.go)) # plugin/cache/ | FUZZ:=$(dir $(wildcard plugin/*/fuzz.go)) # plugin/cache/ | ||||||
| @@ -22,7 +26,9 @@ PLUGINS:=$(foreach f,$(PLUGINS),$(subst /, ,$(f))) # > cache | |||||||
|  |  | ||||||
| .PHONY: echo | .PHONY: echo | ||||||
| echo: | echo: | ||||||
| 	@echo fuzz targets: $(PLUGINS) | 	@echo $(PLUGINS) corefile | ||||||
|  |  | ||||||
|  | all: $(PLUGINS) corefile | ||||||
|  |  | ||||||
| .PHONY: $(PLUGINS) | .PHONY: $(PLUGINS) | ||||||
| $(PLUGINS): echo | $(PLUGINS): echo | ||||||
| @@ -34,7 +40,6 @@ else | |||||||
| 	go-fuzz -bin=./$(@)-fuzz.zip -workdir=fuzz/$(@) | 	go-fuzz -bin=./$(@)-fuzz.zip -workdir=fuzz/$(@) | ||||||
| endif | endif | ||||||
|  |  | ||||||
|  |  | ||||||
| .PHONY: corefile | .PHONY: corefile | ||||||
| corefile: | corefile: | ||||||
| ifeq ($(LIBFUZZER), YES) | ifeq ($(LIBFUZZER), YES) | ||||||
| @@ -45,7 +50,8 @@ else | |||||||
| 	go-fuzz -bin=./test-fuzz.zip -workdir=fuzz/$(@) | 	go-fuzz -bin=./test-fuzz.zip -workdir=fuzz/$(@) | ||||||
| endif | endif | ||||||
|  |  | ||||||
|  | fuzzit: | ||||||
|  | 	wget -O fuzzit https://github.com/fuzzitdev/fuzzit/releases/download/$(FUZZIT)/fuzzit_Linux_x86_64 && chmod +x fuzzit | ||||||
|  |  | ||||||
| .PHONY: clean | .PHONY: clean | ||||||
| clean: | clean: | ||||||
|   | |||||||
| @@ -10,7 +10,7 @@ import ( | |||||||
| 	"github.com/miekg/dns" | 	"github.com/miekg/dns" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // Do will fuzz p - used by gofuzz. See Maefile.fuzz for comments and context. | // Do will fuzz p - used by gofuzz. See Makefile.fuzz for comments and context. | ||||||
| func Do(p plugin.Handler, data []byte) int { | func Do(p plugin.Handler, data []byte) int { | ||||||
| 	ctx := context.TODO() | 	ctx := context.TODO() | ||||||
| 	ret := 1 | 	ret := 1 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user