Use a switch statement in packDomainName

This commit is contained in:
Tom Thorogood 2018-11-26 12:07:46 +10:30
parent 8e6e188a87
commit c12f225763
No known key found for this signature in database
GPG Key ID: 86C63CDA416C6D2F
1 changed files with 5 additions and 5 deletions

10
msg.go
View File

@ -215,8 +215,10 @@ func packDomainName(s string, msg []byte, off int, compression map[string]int, c
begin := 0
bs := []byte(s)
roBs, bsFresh, escapedDot := s, true, false
loop:
for i := 0; i < ls; i++ {
if bs[i] == '\\' {
switch bs[i] {
case '\\':
copy(bs[i:ls-1], bs[i+1:])
ls--
if off+1 > lenmsg {
@ -231,9 +233,7 @@ func packDomainName(s string, msg []byte, off int, compression map[string]int, c
escapedDot = bs[i] == '.'
bsFresh = false
continue
}
if bs[i] == '.' {
case '.':
if i > 0 && bs[i-1] == '.' && !escapedDot {
// two dots back to back is not legal
return lenmsg, labels, ErrRdata
@ -281,7 +281,7 @@ func packDomainName(s string, msg []byte, off int, compression map[string]int, c
if pointer == -1 && compress {
pointer = p // Where to point to
nameoffset = offset // Where to point from
break
break loop
}
}
}