1
0
mirror of https://github.com/golang/go synced 2024-11-20 05:14:41 -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:
Mikio Hara 2012-04-25 12:29:14 +09:00
parent 0681b13437
commit b252fe7002
2 changed files with 34 additions and 1 deletions

View File

@ -97,10 +97,13 @@ func favoriteAddrFamily(net string, laddr, raddr sockaddr, mode string) (family
return syscall.AF_INET6, true return syscall.AF_INET6, true
} }
if mode == "listen" && laddr.isWildcard() { if mode == "listen" && (laddr == nil || laddr.isWildcard()) {
if supportsIPv4map { if supportsIPv4map {
return syscall.AF_INET6, false return syscall.AF_INET6, false
} }
if laddr == nil {
return syscall.AF_INET, false
}
return laddr.family(), false return laddr.family(), false
} }

View File

@ -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()
}
}