Skip to content

dns/dnsmessage: reject names with dots inside label #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions dns/dnsmessage/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ var (
errReserved = errors.New("segment prefix is reserved")
errTooManyPtr = errors.New("too many pointers (>10)")
errInvalidPtr = errors.New("invalid pointer")
errInvalidName = errors.New("invalid dns name")
errNilResouceBody = errors.New("nil resource body")
errResourceLen = errors.New("insufficient data for resource body length")
errSegTooLong = errors.New("segment length too long")
Expand Down Expand Up @@ -2034,6 +2035,15 @@ Loop:
if endOff > len(msg) {
return off, errCalcLen
}

// Reject names containing dots.
// See issue golang/go#56246
for _, v := range msg[currOff:endOff] {
if v == '.' {
return off, errInvalidName
}
}

name = append(name, msg[currOff:endOff]...)
name = append(name, '.')
currOff = endOff
Expand Down
9 changes: 9 additions & 0 deletions dns/dnsmessage/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ func TestName(t *testing.T) {
}
}

func TestNameWithDotsUnpack(t *testing.T) {
name := []byte{3, 'w', '.', 'w', 2, 'g', 'o', 3, 'd', 'e', 'v', 0}
var n Name
_, err := n.unpack(name, 0)
if err != errInvalidName {
t.Fatalf("expected %v, got %v", errInvalidName, err)
}
}

func TestNamePackUnpack(t *testing.T) {
const suffix = ".go.dev."
var longDNSPrefix = strings.Repeat("verylongdomainlabel.", 20)
Expand Down