Skip to content

net: "127.0.0.1:" should be an invalid tcp4 address for ResolveTCPAddr #56144

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
fx-slayer opened this issue Oct 11, 2022 · 6 comments
Closed

Comments

@fx-slayer
Copy link

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

$ go version
go version go1.19.1 darwin/arm64

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="on"
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/zhoudaxing/Library/Caches/go-build"
GOENV="/Users/zhoudaxing/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/zhoudaxing/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/*/go"
GOPRIVATE=""
GOPROXY="https://goproxy.io,direct"
GOROOT="/Users/*/go1.19.1"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/Users/*/go1.19.1/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.19.1"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="0"
GOMOD="*"
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 -arch arm64 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/d0/4_y_gtss2wsfct5v6f6k0zcw0000gn/T/go-build3948008299=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

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

func main() {
	a, e := net.ResolveTCPAddr("tcp4", "127.0.0.1:")
	if e != nil {
		panic(e)
	}
	print(a.String())
}

What did you expect to see?

error is not nil and program panic.

What did you see instead?

127.0.0.1:0
Program exited.

@fx-slayer
Copy link
Author

Hi ,i just found that "127.0.0.1:" is a valid tcp4 address for net. ResolveTCPAddr .
and i don't konw if that is correct or not ,if there is any specification about tcp4 addr i'm glad to konw.

I investigated this issue:
net.SplitHostPort("127.0.0.1:") return a nil error and zero-value port, SplitHostPort do not validate port and it is ok ,but an empty port string should be treated as error.

@fx-slayer fx-slayer changed the title affected/package: net net: "127.0.0.1:" is a valid tcp4 address for ResolveTCPAddr Oct 11, 2022
@thediveo
Copy link
Contributor

why should ":" constitute a valid IPv4 address, with it not being defined in any textual IPv4 address representation.

@fx-slayer
Copy link
Author

why should ":" constitute a valid IPv4 address, with it not being defined in any textual IPv4 address representation.

yes ,it should be invalid ,but in my case it is a valid tcp4 addr. Maybe i should change the title.

@fx-slayer fx-slayer changed the title net: "127.0.0.1:" is a valid tcp4 address for ResolveTCPAddr net: "127.0.0.1:" should be an invalid tcp4 address for ResolveTCPAddr Oct 11, 2022
@Jack-Kingdom
Copy link

Screen Shot 2022-10-12 at 3 31 40 AM

this func assume port is zero if not provide

@seankhliao
Copy link
Member

Working as intended, see #13610

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Oct 12, 2022
@fx-slayer
Copy link
Author

maybe i misunderstood something ,but it is nothing about parsePort and the problem is SplitHostPort treats empty port string(xxx.xxx.xxx.xxx:) as 0. I don't think that's what we expected.

@golang golang locked and limited conversation to collaborators Oct 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants