Fix real dots in domain names

This commit is contained in:
Miek Gieben 2011-02-21 20:56:05 +01:00
parent c7c4d8061e
commit 157c19af4b
3 changed files with 16 additions and 9 deletions

4
TODO
View File

@ -2,12 +2,10 @@ Todo:
* wildcards, in sig gen, sig checking
* Private key file parsing use io.Reader (or the like) - NewReader, NewWriter?
* Tsig generation for replies (request MAC)
* nsupdate
* escaped dots in names \.
* nsupdate, it's there except for the names
Longer term:
* Parsing from strings, going with goyacc and own lexer
* Multi line output?
* NSEC and nsec3 closest encloser helper functions
* pack/Unpack smaller. EDNS 'n stuff can be folded in
* Test impl of nameserver, with a small zone, 1 KSK and online signing

10
msg.go
View File

@ -223,7 +223,15 @@ Loop:
if off+c > len(msg) {
return "", len(msg), false
}
s += string(msg[off:off+c]) + "."
for j := off; j < off+c; j++ {
if msg[j] == '.' {
// literal dot, escape it
s += "\\."
} else {
s += string(msg[j])
}
}
s += "."
off += c
case 0xC0:
// pointer to somewhere else in msg.

View File

@ -138,7 +138,7 @@ func TestQuadA(t *testing.T) {
func TestDotInName(t *testing.T) {
buf := make([]byte, 20)
packDomainName("aa\\.bb.nl", buf, 0)
packDomainName("aa\\.bb.nl.", buf, 0)
// index 3 must be a real dot
if buf[3] != '.' {
t.Log("Dot should be a real dot")
@ -149,9 +149,10 @@ func TestDotInName(t *testing.T) {
t.Log("This must have the value 2")
t.Fail()
}
dom, _, ok := unpackDomainName(buf, 0)
dom, _, _ := unpackDomainName(buf, 0)
// printing it should yield the backspace again
println(dom)
println(ok)
if dom != "aa\\.bb.nl." {
t.Log("Dot should have been escaped: " + dom)
t.Fail()
}
}