Commit 01e13c62 authored by Miek Gieben's avatar Miek Gieben Committed by Yong Tang

plugin/file: New zone should have zero records (#3025)

After calling NewZone the number of records should be zero, but due to
how zone.All() was implemented so empty RRs would be added. This then
fails the == 0 check in xfr.go and put nil in the slice, this then
subsequently panics on the Len().

Fix this making All() smarter when adding records. Added little test to
enfore this.
Signed-off-by: default avatarMiek Gieben <miek@miek.nl>
parent f7b26db9
...@@ -3,6 +3,7 @@ package file ...@@ -3,6 +3,7 @@ package file
import ( import (
"fmt" "fmt"
"strings" "strings"
"testing"
) )
func ExampleZone_All() { func ExampleZone_All() {
...@@ -32,3 +33,11 @@ func ExampleZone_All() { ...@@ -32,3 +33,11 @@ func ExampleZone_All() {
// xfr_test.go:15: a.miek.nl. 1800 IN A 139.162.196.78 // xfr_test.go:15: a.miek.nl. 1800 IN A 139.162.196.78
// xfr_test.go:15: a.miek.nl. 1800 IN AAAA 2a01:7e00::f03c:91ff:fef1:6735 // xfr_test.go:15: a.miek.nl. 1800 IN AAAA 2a01:7e00::f03c:91ff:fef1:6735
} }
func TestAllNewZone(t *testing.T) {
zone := NewZone("example.org.", "stdin")
records := zone.All()
if len(records) != 0 {
t.Errorf("Expected %d records in empty zone, got %d", 0, len(records))
}
}
...@@ -173,15 +173,21 @@ func (z *Zone) All() []dns.RR { ...@@ -173,15 +173,21 @@ func (z *Zone) All() []dns.RR {
records = append(records, a.All()...) records = append(records, a.All()...)
} }
// Either the entire Apex is filled or none it, this isn't enforced here though.
if len(z.Apex.SIGNS) > 0 { if len(z.Apex.SIGNS) > 0 {
records = append(z.Apex.SIGNS, records...) records = append(z.Apex.SIGNS, records...)
} }
records = append(z.Apex.NS, records...) if len(z.Apex.NS) > 0 {
records = append(z.Apex.NS, records...)
}
if len(z.Apex.SIGSOA) > 0 { if len(z.Apex.SIGSOA) > 0 {
records = append(z.Apex.SIGSOA, records...) records = append(z.Apex.SIGSOA, records...)
} }
return append([]dns.RR{z.Apex.SOA}, records...) if z.Apex.SOA != nil {
return append([]dns.RR{z.Apex.SOA}, records...)
}
return records
} }
// NameFromRight returns the labels from the right, staring with the // NameFromRight returns the labels from the right, staring with the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment