If we add a dot to a name, be sure to remove one from the length
This commit is contained in:
parent
cb4d52c110
commit
77b60231e7
18
defaults.go
18
defaults.go
|
@ -205,11 +205,15 @@ func IsDomainName(s string) (uint8, uint8, bool) { // copied from net package.
|
|||
if l == 0 || l > 255 {
|
||||
return 0, 0, false
|
||||
}
|
||||
// Simplify checking loop: make the name end in a dot
|
||||
// Don't call Fqdn() to save another len(s)
|
||||
longer := 0
|
||||
// Simplify checking loop: make the name end in a dot.
|
||||
// Don't call Fqdn() to save another len(s).
|
||||
// Keep in mind that if we do this, we report a longer
|
||||
// length
|
||||
if s[l-1] != '.' {
|
||||
s += "."
|
||||
l++
|
||||
longer = 1
|
||||
}
|
||||
last := byte('.')
|
||||
ok := false // ok once we've seen a letter
|
||||
|
@ -219,7 +223,7 @@ func IsDomainName(s string) (uint8, uint8, bool) { // copied from net package.
|
|||
c := s[i]
|
||||
switch {
|
||||
default:
|
||||
return 0, uint8(l), false
|
||||
return 0, uint8(l - longer), false
|
||||
case 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '_' || c == '*':
|
||||
ok = true
|
||||
partlen++
|
||||
|
@ -231,27 +235,27 @@ func IsDomainName(s string) (uint8, uint8, bool) { // copied from net package.
|
|||
case c == '-':
|
||||
// byte before dash cannot be dot
|
||||
if last == '.' {
|
||||
return 0, uint8(l), false
|
||||
return 0, uint8(l - longer), false
|
||||
}
|
||||
partlen++
|
||||
case c == '.':
|
||||
// byte before dot cannot be dot, dash
|
||||
if last == '.' || last == '-' {
|
||||
return 0, uint8(l), false
|
||||
return 0, uint8(l - longer), false
|
||||
}
|
||||
if last == '\\' { // Ok, escaped dot.
|
||||
partlen++
|
||||
break
|
||||
}
|
||||
if partlen > 63 || partlen == 0 {
|
||||
return 0, uint8(l), false
|
||||
return 0, uint8(l - longer), false
|
||||
}
|
||||
partlen = 0
|
||||
labels++
|
||||
}
|
||||
last = c
|
||||
}
|
||||
return labels, uint8(l), ok
|
||||
return labels, uint8(l - longer), ok
|
||||
}
|
||||
|
||||
// IsFqdn checks if a domain name is fully qualified
|
||||
|
|
Loading…
Reference in New Issue