diff --git a/plugin/file/file.go b/plugin/file/file.go index 67b81e9a5..21039d8ec 100644 --- a/plugin/file/file.go +++ b/plugin/file/file.go @@ -166,15 +166,11 @@ func Parse(f io.Reader, origin, fileName string, serial int64) (*Zone, error) { return nil, err } } - if !seenSOA { - return nil, fmt.Errorf("file %q has no SOA record for origin %s", fileName, origin) - } if zp.Err() != nil { return nil, fmt.Errorf("failed to parse file %q for origin %s with error %v", fileName, origin, zp.Err()) } - - if err := zp.Err(); err != nil { - return nil, err + if !seenSOA { + return nil, fmt.Errorf("file %q has no SOA record for origin %s", fileName, origin) } return z, nil diff --git a/plugin/file/file_test.go b/plugin/file/file_test.go index e1afc7f49..dd3be334a 100644 --- a/plugin/file/file_test.go +++ b/plugin/file/file_test.go @@ -57,3 +57,53 @@ www IN A 192.168.0.14 mail IN A 192.168.0.15 imap IN CNAME mail ` + +func TestParseMalformedSOA(t *testing.T) { + _, err := Parse(strings.NewReader(dbMalformedSOA), "example.org.", "stdin", 0) + if err == nil { + t.Fatalf("Zone %q should have failed to load", "example.org.") + } + if !strings.Contains(err.Error(), "bad SOA zone parameter") { + t.Fatalf("Expected parse error containing 'bad SOA zone parameter', got: %s", err) + } +} + +const dbMalformedSOA = ` +$TTL 1M +$ORIGIN example.org. + +@ IN SOA ns1.example.com. admin.example.com. ( + abc ; Serial - invalid + 1200 ; Refresh + 144 ; Retry + 1814400 ; Expire + 2h ) ; Minimum +@ IN NS ns1.example.com. + +www IN A 192.168.0.14 +` + +func TestParseSOASerialTooLarge(t *testing.T) { + _, err := Parse(strings.NewReader(dbSOASerialTooLarge), "example.org.", "stdin", 0) + if err == nil { + t.Fatalf("Zone %q should have failed to load", "example.org.") + } + if !strings.Contains(err.Error(), "bad SOA zone parameter") { + t.Fatalf("Expected parse error containing 'bad SOA zone parameter', got: %s", err) + } +} + +const dbSOASerialTooLarge = ` +$TTL 1M +$ORIGIN example.org. + +@ IN SOA ns1.example.com. admin.example.com. ( + 202512200817 ; Serial - exceeds 32-bit uint + 1200 ; Refresh + 144 ; Retry + 1814400 ; Expire + 2h ) ; Minimum +@ IN NS ns1.example.com. + +www IN A 192.168.0.14 +`