Skip to content

net: LookupCNAME returns empty string if entry from /etc/hosts is used #44741

Closed
@riton

Description

@riton

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

$ go version
go version go1.16 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=""
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/user/go/pkg/mod"
GONOPROXY="*.private-domain.fr"
GONOSUMDB="*.private-domain.fr"
GOOS="linux"
GOPATH="/home/user/go"
GOPRIVATE="*.private-domain.fr"
GOPROXY="direct"
GOROOT="/opt/go/go1.16"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/go/go1.16/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build937784123=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I'm trying to resolve a name that is present in my /etc/hosts using LookupCNAME

The simple program I'm using is:

package main                                               
                                                           
import (                                                   
        "fmt"                                              
        "net"                                              
        "os"                                               
)                                                          
                                                           
func main() {                                              
        name, err := net.LookupCNAME(os.Args[1])           
        fmt.Printf("name = %q, err = %v\n", name, err)     
}                                                          

The content of my /etc/hosts is:

140.82.121.4 github.com

(the behavior exists with other domains / adresses)

What did you expect to see?

Same behavior using cgo resolver and pure go resolver:

with cgo resolver`

$ GODEBUG="netdns=3" go run . github.com
go package net: dynamic selection of DNS resolver
go package net: hostLookupOrder() = cgo
name = "github.com.", err = <nil>

with pure go resolver`

$ GODEBUG="netdns=go+3" go run . github.com                 
go package net: GODEBUG setting forcing use of Go's resolver
go package net: hostLookupOrder() = files,dns               
go package net: hostLookupOrder(github.com) = files,dns     
name = "github.com.", err = <nil>                                                        

What did you see instead?

with cgo resolver`

$ GODEBUG="netdns=3" go run . github.com
go package net: dynamic selection of DNS resolver
go package net: hostLookupOrder() = cgo
name = "github.com.", err = <nil>

with pure go resolver`

$ GODEBUG="netdns=go+3" go run . github.com                 
go package net: GODEBUG setting forcing use of Go's resolver
go package net: hostLookupOrder() = files,dns               
go package net: hostLookupOrder(github.com) = files,dns     
name = "", err = <nil>                                                        

Pure GO returns an empty string while cgo resolves the name properly.

Extra informations

It seems that this behavior is from the dnsmessage.Name{} returned from https://github.com/golang/go/blob/go1.16/src/net/dnsclient_unix.go#L569 .

As soon as the /etc/hosts entry is removed, the behavior difference disappears.

Thanks in advance for helping me understand this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions