mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 17:53:21 -04:00 
			
		
		
		
	When CoreDNS starts up and can't get a zone transfer going the Apex is empty. This `nil` is then transformed into wireformat, which fails with a nil pointer dereference in Go DNS. In this case we should just return SERVFAIL, because we don't have any info (yet). Note the lookup code returned NXDOMAIN, which is correct from a lookup standpoint, but also invalidates every name in the future loaded zone. Anyway, look for an apex before doing the lookup and return SERVFAIL if nothing is found. Fixes #679
		
			
				
	
	
		
			48 lines
		
	
	
		
			1017 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			1017 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package test
 | |
| 
 | |
| import (
 | |
| 	"io/ioutil"
 | |
| 	"log"
 | |
| 	"testing"
 | |
| 
 | |
| 	"github.com/coredns/coredns/middleware/proxy"
 | |
| 	"github.com/coredns/coredns/middleware/test"
 | |
| 	"github.com/coredns/coredns/request"
 | |
| 
 | |
| 	"github.com/miekg/dns"
 | |
| )
 | |
| 
 | |
| func TestEmptySecondaryZone(t *testing.T) {
 | |
| 	// Corefile that fails to transfer example.org.
 | |
| 	corefile := `example.org:0 {
 | |
| 		secondary {
 | |
| 			transfer from 127.0.0.1:1717
 | |
| 		}
 | |
| 	}
 | |
| `
 | |
| 
 | |
| 	i, err := CoreDNSServer(corefile)
 | |
| 	if err != nil {
 | |
| 		t.Fatalf("Could not get CoreDNS serving instance: %s", err)
 | |
| 	}
 | |
| 
 | |
| 	udp, _ := CoreDNSServerPorts(i, 0)
 | |
| 	if udp == "" {
 | |
| 		t.Fatal("Could not get UDP listening port")
 | |
| 	}
 | |
| 	defer i.Stop()
 | |
| 
 | |
| 	log.SetOutput(ioutil.Discard)
 | |
| 
 | |
| 	p := proxy.NewLookup([]string{udp})
 | |
| 	state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
 | |
| 
 | |
| 	resp, err := p.Lookup(state, "www.example.org.", dns.TypeA)
 | |
| 	if err != nil {
 | |
| 		t.Fatal("Expected to receive reply, but didn't")
 | |
| 	}
 | |
| 	if resp.Rcode != dns.RcodeServerFailure {
 | |
| 		t.Fatalf("Expected reply to be a SERVFAIL, got %d", resp.Rcode)
 | |
| 	}
 | |
| }
 |