Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return error for empty target #1627

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ func IsDomainName(s string) (labels int, ok bool) {

const lenmsg = 256

if s == "\n" {
return 0, false
}

if len(s) == 0 { // Ok, for instance when dealing with update RR without any rdata.
return 0, false
}
Expand Down
1 change: 1 addition & 0 deletions labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func TestIsDomainName(t *testing.T) {
lab int
}
names := map[string]*ret{
"\n": {false, 0},
".": {true, 1},
"..": {false, 0},
"double-dot..test": {false, 1},
Expand Down
16 changes: 16 additions & 0 deletions scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,22 @@ func TestZoneParserAddressAAAA(t *testing.T) {
}
}

func TestZoneParserTargetBad(t *testing.T) {
records := []string{
"bad.example.org. CNAME ; bad cname",
"bad.example.org. HTTPS 10 ; bad https",
"bad.example.org. MX 10 ; bad mx",
"bad.example.org. SRV 1 0 80 ; bad srv",
}

for _, record := range records {
const expect = "bad "
if got, err := NewRR(record); err == nil || !strings.Contains(err.Error(), expect) {
t.Errorf("NewRR(%v) = %v, want err to contain %q", record, got, expect)
}
}
}

func TestZoneParserAddressBad(t *testing.T) {
records := []string{
"1.bad.example.org. 600 IN A ::1",
Expand Down