If we add a dot to a name, be sure to remove one from the length

This commit is contained in:
Miek Gieben 2012-02-05 11:33:55 +01:00
parent cb4d52c110
commit 77b60231e7
5 changed files with 35 additions and 29 deletions

View File

@ -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

View File

@ -166,6 +166,8 @@ func parseZone(r io.Reader, f string, t chan Token, include int) {
t <- Token{Error: &ParseError{f, "bad owner name", l}}
return
}
println(l.token)
println(len(l.token), ld)
if h.Name[ld-1] != '.' {
h.Name += origin
}