diff options
author | Bryan Mills <bcmills@google.com> | 2021-12-07 20:34:46 +0000 |
---|---|---|
committer | Bryan Mills <bcmills@google.com> | 2021-12-08 15:31:54 +0000 |
commit | 2c85fcd47d6804d94a1fa4da65f756200ecf57a8 (patch) | |
tree | 53de00f9242f6bfb0a055e5a16d6387b4d113360 /src/net | |
parent | 9fe77de3c198848b972915245e41ff26439b08aa (diff) | |
download | go-2c85fcd47d6804d94a1fa4da65f756200ecf57a8.tar.gz go-2c85fcd47d6804d94a1fa4da65f756200ecf57a8.zip |
Revert "net: in (*netFD).dial, use the passed in local address if getsockname fails"
This reverts CL 366536
Reason for revert: may have caused #50033 due to an invalid or partially-populated *TCPAddr
Fixes #50033
Change-Id: Ia29ca4116503dba65d56e89caa46ba1c848d421a
Reviewed-on: https://go-review.googlesource.com/c/go/+/369982
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/server_test.go | 10 | ||||
-rw-r--r-- | src/net/sock_posix.go | 16 |
2 files changed, 6 insertions, 20 deletions
diff --git a/src/net/server_test.go b/src/net/server_test.go index b69cd29289..33d33b0337 100644 --- a/src/net/server_test.go +++ b/src/net/server_test.go @@ -200,17 +200,9 @@ func TestUnixAndUnixpacketServer(t *testing.T) { if c == nil { panic("Dial returned a nil Conn") } - rc := reflect.ValueOf(c) - if rc.IsNil() { + if rc := reflect.ValueOf(c); rc.Kind() == reflect.Pointer && rc.IsNil() { panic(fmt.Sprintf("Dial returned a nil %T", c)) } - fd := rc.Elem().FieldByName("fd") - if fd.IsNil() { - panic(fmt.Sprintf("Dial returned a %T with a nil fd", c)) - } - if addr := fd.Elem().FieldByName("laddr"); addr.IsNil() { - panic(fmt.Sprintf("Dial returned a %T whose fd has a nil laddr", c)) - } addr := c.LocalAddr() if addr == nil { panic(fmt.Sprintf("(%T).LocalAddr returned a nil Addr", c)) diff --git a/src/net/sock_posix.go b/src/net/sock_posix.go index 603fb2bb64..98a48229c7 100644 --- a/src/net/sock_posix.go +++ b/src/net/sock_posix.go @@ -156,24 +156,18 @@ func (fd *netFD) dial(ctx context.Context, laddr, raddr sockaddr, ctrlFn func(st } } // Record the local and remote addresses from the actual socket. - // For the local address, use - // 1) the one returned by Getsockname, if that succeeds; or - // 2) the one passed to us as the laddr parameter; or - // 3) nil. + // Get the local address by calling Getsockname. // For the remote address, use // 1) the one returned by the connect method, if any; or // 2) the one from Getpeername, if it succeeds; or // 3) the one passed to us as the raddr parameter. - var laddrName Addr = laddr - if lsa, err := syscall.Getsockname(fd.pfd.Sysfd); err == nil { - laddrName = fd.addrFunc()(lsa) - } + lsa, _ = syscall.Getsockname(fd.pfd.Sysfd) if crsa != nil { - fd.setAddr(laddrName, fd.addrFunc()(crsa)) + fd.setAddr(fd.addrFunc()(lsa), fd.addrFunc()(crsa)) } else if rsa, _ = syscall.Getpeername(fd.pfd.Sysfd); rsa != nil { - fd.setAddr(laddrName, fd.addrFunc()(rsa)) + fd.setAddr(fd.addrFunc()(lsa), fd.addrFunc()(rsa)) } else { - fd.setAddr(laddrName, raddr) + fd.setAddr(fd.addrFunc()(lsa), raddr) } return nil } |