mirror of
https://github.com/miekg/dns.git
synced 2025-12-16 17:21:17 +01:00
limiting domain names to 255/63 octets/labels (#463)
This commit is contained in:
parent
75229eecb7
commit
0b729df06c
13
msg.go
13
msg.go
@ -327,6 +327,7 @@ End:
|
|||||||
// UnpackDomainName unpacks a domain name into a string.
|
// UnpackDomainName unpacks a domain name into a string.
|
||||||
func UnpackDomainName(msg []byte, off int) (string, int, error) {
|
func UnpackDomainName(msg []byte, off int) (string, int, error) {
|
||||||
s := make([]byte, 0, 64)
|
s := make([]byte, 0, 64)
|
||||||
|
labels := 0
|
||||||
off1 := 0
|
off1 := 0
|
||||||
lenmsg := len(msg)
|
lenmsg := len(msg)
|
||||||
ptr := 0 // number of pointers followed
|
ptr := 0 // number of pointers followed
|
||||||
@ -369,6 +370,15 @@ Loop:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// never exceed the allowed label count lenght (63)
|
||||||
|
if labels >= 63 {
|
||||||
|
return "", lenmsg, &Error{err: "name exceeds 63 labels"}
|
||||||
|
}
|
||||||
|
labels += 1
|
||||||
|
// never exceed the allowed doman name length (255 octets)
|
||||||
|
if len(s) >= 255 {
|
||||||
|
return "", lenmsg, &Error{err: "name exceeded allowed 255 octets"}
|
||||||
|
}
|
||||||
s = append(s, '.')
|
s = append(s, '.')
|
||||||
off += c
|
off += c
|
||||||
case 0xC0:
|
case 0xC0:
|
||||||
@ -388,6 +398,9 @@ Loop:
|
|||||||
if ptr++; ptr > 10 {
|
if ptr++; ptr > 10 {
|
||||||
return "", lenmsg, &Error{err: "too many compression pointers"}
|
return "", lenmsg, &Error{err: "too many compression pointers"}
|
||||||
}
|
}
|
||||||
|
// pointer should guarantee that it advances and points forwards at least
|
||||||
|
// but the condition on previous three lines guarantees that it's
|
||||||
|
// at least loop-free
|
||||||
off = (c^0xC0)<<8 | int(c1)
|
off = (c^0xC0)<<8 | int(c1)
|
||||||
default:
|
default:
|
||||||
// 0x80 and 0x40 are reserved
|
// 0x80 and 0x40 are reserved
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user