Skip to content
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

net: netgo resolver cannot lookup 254 characters FQDN #54285

Closed
yosida95 opened this issue Aug 5, 2022 · 3 comments
Closed

net: netgo resolver cannot lookup 254 characters FQDN #54285

yosida95 opened this issue Aug 5, 2022 · 3 comments
Labels
NeedsInvestigation

Comments

@yosida95
Copy link

yosida95 commented Aug 5, 2022

What version of Go are you using (go version)?

$ go version
go version go1.19 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/home/yosida95/proj/bin"
GOCACHE="/home/yosida95/.cache/go-build"
GOENV="/home/yosida95/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/yosida95/proj/pkg/mod"
GOOS="linux"
GOPATH="/home/yosida95/proj"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/go/1.19"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/go/1.19/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3904822855=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Lookup for 254 characters FQDN, maximum length as per the DNS spec.

https://go.dev/play/p/QMYRUTEvL2Y

In the above play I use LookupTXT, but other Lookup* functions are also affected by this bug when built with -tags netgo.

What did you expect to see?

Successful response or NXDOMAIN

What did you see instead?

&net.DNSError{Err:"cannot unmarshal DNS message", Server: ""}

In dnsclient_unix.go, *dnsConfig.nameList rejects 254 characters FQDN instead of rejecting 254 characters non-FQDN.

rooted := l > 0 && name[l-1] == '.'
if l > 254 || l == 254 && rooted {

It also means *dnsConfig.nameList accepts 254 characters non-FQDN and generates invalid 255 characters FQDN.

name += "."
l++
// Build list of search choices.
names := make([]string, 0, 1+len(conf.search))
// If name has enough dots, try unsuffixed first.
if hasNdots {
names = append(names, name)
}

On the other hand, isDomainName does correct FQDN handling.

if l == 0 || l > 254 || l == 254 && s[l-1] != '.' {

@mateusz834
Copy link
Contributor

mateusz834 commented Aug 5, 2022

LookupHost has even a different behaviour than the LookupTXT:

func main() {
        suffix := ".example.net."
        name := strings.Repeat("verylong.", 27)[:254-len(suffix)] + suffix
        fmt.Println(len(name), name)

        d, err := net.LookupHost(name)
        fmt.Println(d, err)
}
[mateusz@arch isstes]$ GODEBUG=netdns=go+3 go run main.go
254 verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylon.example.net.
go package net: confVal.netCgo = false  netGo = true
go package net: GODEBUG setting forcing use of Go's resolver
go package net: hostLookupOrder(verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylong.verylon.example.net) = files,dns
[] <nil>

@gopherbot
Copy link

gopherbot commented Aug 5, 2022

Change https://go.dev/cl/421674 mentions this issue: net: dns fix 254 char fqdn

@seankhliao
Copy link
Member

seankhliao commented Aug 5, 2022

cc @neild

@seankhliao seankhliao added the NeedsInvestigation label Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants