Skip to content

Commit

Permalink
Disallow names that start with '.' in IsDomainName() (miekg#1376)
Browse files Browse the repository at this point in the history
* Disallow names that start with '.' in IsDomainName()

* Also update packDomain()
  • Loading branch information
shane-ns1 authored and aanm committed Jul 29, 2022
1 parent d3125e0 commit edeb6e7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions defaults.go
Expand Up @@ -218,6 +218,11 @@ func IsDomainName(s string) (labels int, ok bool) {

wasDot = false
case '.':
if i == 0 && len(s) > 1 {
// leading dots are not legal except for the root zone
return labels, false
}

if wasDot {
// two dots back to back is not legal
return labels, false
Expand Down
5 changes: 4 additions & 1 deletion labels_test.go
Expand Up @@ -176,7 +176,10 @@ func TestIsDomainName(t *testing.T) {
lab int
}
names := map[string]*ret{
"..": {false, 1},
".": {true, 1},
"..": {false, 0},
"double-dot..test": {false, 1},
".leading-dot.test": {false, 0},
"@.": {true, 1},
"www.example.com": {true, 3},
"www.e%ample.com": {true, 3},
Expand Down
5 changes: 5 additions & 0 deletions msg.go
Expand Up @@ -265,6 +265,11 @@ loop:

wasDot = false
case '.':
if i == 0 && len(s) > 1 {
// leading dots are not legal except for the root zone
return len(msg), ErrRdata
}

if wasDot {
// two dots back to back is not legal
return len(msg), ErrRdata
Expand Down

0 comments on commit edeb6e7

Please sign in to comment.