Commit b252fe70 authored by Mikio Hara's avatar Mikio Hara

net: fix crash of Listen with "" or nil laddr

Fixes #3584.

R=dave, dsymonds, rsc
CC=golang-dev
https://golang.org/cl/6119043
parent 0681b134
......@@ -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()
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment