Skip to content

Commit 51198de

Browse files
authored
Fix encoding of Target="." (#62)
1 parent 0ce285e commit 51198de

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

dns/message.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ func (m Message) Bytes() []byte {
309309

310310
func (rr RR) Bytes() []byte {
311311
s := cryptobyte.NewBuilder(nil)
312-
if len(rr.Name) > 0 {
313-
for _, p := range strings.Split(rr.Name, ".") {
312+
if name := strings.TrimSuffix(rr.Name, "."); len(name) > 0 {
313+
for _, p := range strings.Split(name, ".") {
314314
s.AddUint8LengthPrefixed(func(s *cryptobyte.Builder) {
315315
s.AddBytes([]byte(p))
316316
})
@@ -326,7 +326,7 @@ func (rr RR) Bytes() []byte {
326326
s.AddBytes([]byte(data))
327327
case string:
328328
if rr.Type == 2 || rr.Type == 5 || rr.Type == 12 { // NS, CNAME, PTR
329-
for _, p := range strings.Split(data, ".") {
329+
for _, p := range strings.Split(strings.TrimSuffix(data, "."), ".") {
330330
s.AddUint8LengthPrefixed(func(s *cryptobyte.Builder) {
331331
s.AddBytes([]byte(p))
332332
})
@@ -342,8 +342,8 @@ func (rr RR) Bytes() []byte {
342342
}
343343
case HTTPS:
344344
s.AddUint16(data.Priority)
345-
if len(data.Target) > 0 {
346-
for _, p := range strings.Split(data.Target, ".") {
345+
if target := strings.TrimSuffix(data.Target, "."); len(target) > 0 {
346+
for _, p := range strings.Split(target, ".") {
347347
s.AddUint8LengthPrefixed(func(s *cryptobyte.Builder) {
348348
s.AddBytes([]byte(p))
349349
})

0 commit comments

Comments
 (0)