2017-09-29 22:28:13 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# Makefile for fuzzing
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-19 08:06:25 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# With https://app.fuzzit.dev/ we are continuously fuzzing CoreDNS.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-29 22:28:13 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# 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>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# e.g.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#
							 | 
						
					
						
							
								
									
										
										
										
											2019-03-03 23:32:38 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# 	make -f Makefile.fuzz forward
							 | 
						
					
						
							
								
									
										
										
										
											2018-12-17 07:49:15 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-29 22:28:13 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# Each plugin that wants to join the fuzzing fray only needs to add a fuzz.go that calls
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-21 16:08:55 -04:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# the plugin's ServeDNS and used the plugin/pkg/fuzz for the Do function.
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-29 22:28:13 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-19 08:06:25 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# Installing go-fuzz is very tricky because it does not support Go modules, see the `Makefile`
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# for the current trickery. The following may do the trick:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# GO111MODULE=off go get github.com/dvyukov/go-fuzz/go-fuzz-build
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-29 22:28:13 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-12-17 07:49:15 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								REPO:="github.com/coredns/coredns"
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-26 08:15:05 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								FUZZIT:=v2.4.35
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-18 11:40:59 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# set LIBFUZZER=YES to build libfuzzer compatible targets
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-29 22:28:13 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								FUZZ:=$(dir $(wildcard plugin/*/fuzz.go)) # plugin/cache/
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								PLUGINS:=$(foreach f,$(FUZZ),$(subst plugin, ,$(f:/=))) # > /cache
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								PLUGINS:=$(foreach f,$(PLUGINS),$(subst /, ,$(f))) # > cache
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								.PHONY: echo
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								echo:
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-19 08:06:25 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									@echo $(PLUGINS) corefile
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								all: $(PLUGINS) corefile
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-29 22:28:13 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								.PHONY: $(PLUGINS)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								$(PLUGINS): echo
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-18 11:40:59 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								ifeq ($(LIBFUZZER), YES)
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-25 18:32:44 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									go-fuzz-build -libfuzzer -o $(@).a ./plugin/$(@)
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-18 11:40:59 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									clang -fsanitize=fuzzer $(@).a -o $(@)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								else
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-25 18:32:44 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									go-fuzz-build $(REPO)/plugin/$(@)
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-29 22:28:13 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									go-fuzz -bin=./$(@)-fuzz.zip -workdir=fuzz/$(@)
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-18 11:40:59 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								endif
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-12-17 07:49:15 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								.PHONY: corefile
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								corefile:
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-18 11:40:59 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								ifeq ($(LIBFUZZER), YES)
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-25 18:32:44 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									go-fuzz-build -libfuzzer -o $(@).a ./test
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-18 11:40:59 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									clang -fsanitize=fuzzer $(@).a -o $(@)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								else
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-25 18:32:44 +05:30
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									go-fuzz-build $(REPO)/test
							 | 
						
					
						
							
								
									
										
										
										
											2018-12-17 07:49:15 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									go-fuzz -bin=./test-fuzz.zip -workdir=fuzz/$(@)
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-18 11:40:59 +03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								endif
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-19 08:06:25 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								fuzzit:
							 | 
						
					
						
							
								
									
										
										
										
											2019-08-26 09:33:20 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									wget --quiet -O fuzzit https://github.com/fuzzitdev/fuzzit/releases/download/$(FUZZIT)/fuzzit_Linux_x86_64 && chmod +x fuzzit
							 | 
						
					
						
							
								
									
										
										
										
											2018-12-17 07:49:15 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2017-09-29 22:28:13 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								.PHONY: clean
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								clean:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									rm *-fuzz.zip
							 |