Disallow names that start with '.' in IsDomainName() (#1376)
* Disallow names that start with '.' in IsDomainName() * Also update packDomain()
This commit is contained in:
parent
5521648610
commit
7413c83334
|
@ -218,6 +218,11 @@ func IsDomainName(s string) (labels int, ok bool) {
|
||||||
|
|
||||||
wasDot = false
|
wasDot = false
|
||||||
case '.':
|
case '.':
|
||||||
|
if i == 0 && len(s) > 1 {
|
||||||
|
// leading dots are not legal except for the root zone
|
||||||
|
return labels, false
|
||||||
|
}
|
||||||
|
|
||||||
if wasDot {
|
if wasDot {
|
||||||
// two dots back to back is not legal
|
// two dots back to back is not legal
|
||||||
return labels, false
|
return labels, false
|
||||||
|
|
|
@ -176,7 +176,10 @@ func TestIsDomainName(t *testing.T) {
|
||||||
lab int
|
lab int
|
||||||
}
|
}
|
||||||
names := map[string]*ret{
|
names := map[string]*ret{
|
||||||
"..": {false, 1},
|
".": {true, 1},
|
||||||
|
"..": {false, 0},
|
||||||
|
"double-dot..test": {false, 1},
|
||||||
|
".leading-dot.test": {false, 0},
|
||||||
"@.": {true, 1},
|
"@.": {true, 1},
|
||||||
"www.example.com": {true, 3},
|
"www.example.com": {true, 3},
|
||||||
"www.e%ample.com": {true, 3},
|
"www.e%ample.com": {true, 3},
|
||||||
|
|
5
msg.go
5
msg.go
|
@ -265,6 +265,11 @@ loop:
|
||||||
|
|
||||||
wasDot = false
|
wasDot = false
|
||||||
case '.':
|
case '.':
|
||||||
|
if i == 0 && len(s) > 1 {
|
||||||
|
// leading dots are not legal except for the root zone
|
||||||
|
return len(msg), ErrRdata
|
||||||
|
}
|
||||||
|
|
||||||
if wasDot {
|
if wasDot {
|
||||||
// two dots back to back is not legal
|
// two dots back to back is not legal
|
||||||
return len(msg), ErrRdata
|
return len(msg), ErrRdata
|
||||||
|
|
Loading…
Reference in New Issue