mirror of
https://github.com/golang/go
synced 2024-11-20 05:44:44 -07:00
net: fix crash of Listen with "" or nil laddr
Fixes #3584. R=dave, dsymonds, rsc CC=golang-dev https://golang.org/cl/6119043
This commit is contained in:
parent
0681b13437
commit
b252fe7002
@ -97,10 +97,13 @@ func favoriteAddrFamily(net string, laddr, raddr sockaddr, mode string) (family
|
||||
return syscall.AF_INET6, true
|
||||
}
|
||||
|
||||
if mode == "listen" && laddr.isWildcard() {
|
||||
if mode == "listen" && (laddr == nil || laddr.isWildcard()) {
|
||||
if supportsIPv4map {
|
||||
return syscall.AF_INET6, false
|
||||
}
|
||||
if laddr == nil {
|
||||
return syscall.AF_INET, false
|
||||
}
|
||||
return laddr.family(), false
|
||||
}
|
||||
|
||||
|
@ -536,3 +536,33 @@ func TestProhibitionaryDialArgs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestWildWildcardListener(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "plan9":
|
||||
t.Logf("skipping test on %q", runtime.GOOS)
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if recover() != nil {
|
||||
t.Fatalf("panicked")
|
||||
}
|
||||
}()
|
||||
|
||||
if ln, err := Listen("tcp", ""); err != nil {
|
||||
ln.Close()
|
||||
}
|
||||
if ln, err := ListenPacket("udp", ""); err != nil {
|
||||
ln.Close()
|
||||
}
|
||||
if ln, err := ListenTCP("tcp", nil); err != nil {
|
||||
ln.Close()
|
||||
}
|
||||
if ln, err := ListenUDP("udp", nil); err != nil {
|
||||
ln.Close()
|
||||
}
|
||||
if ln, err := ListenIP("ip:icmp", nil); err != nil {
|
||||
ln.Close()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user