Skip to content

Commit

Permalink
Return error for empty target
Browse files Browse the repository at this point in the history
  • Loading branch information
taoso committed Feb 26, 2025
1 parent 97c29ff commit adbead6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,10 @@ func stringToCm(token string) (e, m uint8, ok bool) {
}

func toAbsoluteName(name, origin string) (absolute string, ok bool) {
if name == "\n" {
return "", false
}

// check for an explicit origin reference
if name == "@" {
// require a nonempty origin
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

0 comments on commit adbead6

Please sign in to comment.