From e78414ef75607394ad7d917824f07f381df2eafa Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sun, 4 Jun 2017 13:30:08 +0100 Subject: [PATCH] xfr: return sane error when !RcodeSuccess (#496) When the server returns a non succesful rcode, return that to the caller in stead of the "bad soa" of before. "dns: bad xfr rcode: " is now returned. Fixes #467 --- xfr.go | 11 +++++++++++ xfr_test.go | 27 +++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/xfr.go b/xfr.go index 7346deff..576c5590 100644 --- a/xfr.go +++ b/xfr.go @@ -1,6 +1,7 @@ package dns import ( + "fmt" "time" ) @@ -81,6 +82,10 @@ func (t *Transfer) inAxfr(id uint16, c chan *Envelope) { return } if first { + if in.Rcode != RcodeSuccess { + c <- &Envelope{in.Answer, &Error{err: fmt.Sprintf(errXFR, in.Rcode)}} + return + } if !isSOAFirst(in) { c <- &Envelope{in.Answer, ErrSoa} return @@ -126,6 +131,10 @@ func (t *Transfer) inIxfr(id uint16, c chan *Envelope) { return } if first { + if in.Rcode != RcodeSuccess { + c <- &Envelope{in.Answer, &Error{err: fmt.Sprintf(errXFR, in.Rcode)}} + return + } // A single SOA RR signals "no changes" if len(in.Answer) == 1 && isSOAFirst(in) { c <- &Envelope{in.Answer, nil} @@ -242,3 +251,5 @@ func isSOALast(in *Msg) bool { } return false } + +const errXFR = "bad xfr rcode: %d" diff --git a/xfr_test.go b/xfr_test.go index 1337eec6..a478963a 100644 --- a/xfr_test.go +++ b/xfr_test.go @@ -4,6 +4,7 @@ package dns import ( "net" + "strings" "testing" "time" ) @@ -16,8 +17,7 @@ func getIP(s string) string { return a[0] } -// flaky, need to setup local server and test from -// that. +// flaky, need to setup local server and test from that. func TestAXFR_Miek(t *testing.T) { // This test runs against a server maintained by Miek if testing.Short() { @@ -159,3 +159,26 @@ func testAXFRSIDN(t *testing.T, host, alg string) { } } } + +func TestAXFRFailNotAuth(t *testing.T) { + // This tests run against a server maintained by SIDN labs, see: + // https://workbench.sidnlabs.nl/ + if testing.Short() { + return + } + x := new(Transfer) + + m := new(Msg) + m.SetAxfr("sidnlabs.nl.") + c, err := x.In(m, "yadifa.sidnlabs.nl:53") + if err != nil { + t.Fatal(err) + } + for e := range c { + if e.Error != nil { + if !strings.HasPrefix(e.Error.Error(), "dns: bad xfr rcode:") { + t.Fatal(e.Error) + } + } + } +}