Skip to content

Commit 2c85fcd

Browse files
author
Bryan Mills
committed
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>
1 parent 9fe77de commit 2c85fcd

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

src/net/server_test.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,9 @@ func TestUnixAndUnixpacketServer(t *testing.T) {
200200
if c == nil {
201201
panic("Dial returned a nil Conn")
202202
}
203-
rc := reflect.ValueOf(c)
204-
if rc.IsNil() {
203+
if rc := reflect.ValueOf(c); rc.Kind() == reflect.Pointer && rc.IsNil() {
205204
panic(fmt.Sprintf("Dial returned a nil %T", c))
206205
}
207-
fd := rc.Elem().FieldByName("fd")
208-
if fd.IsNil() {
209-
panic(fmt.Sprintf("Dial returned a %T with a nil fd", c))
210-
}
211-
if addr := fd.Elem().FieldByName("laddr"); addr.IsNil() {
212-
panic(fmt.Sprintf("Dial returned a %T whose fd has a nil laddr", c))
213-
}
214206
addr := c.LocalAddr()
215207
if addr == nil {
216208
panic(fmt.Sprintf("(%T).LocalAddr returned a nil Addr", c))

src/net/sock_posix.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,24 +156,18 @@ func (fd *netFD) dial(ctx context.Context, laddr, raddr sockaddr, ctrlFn func(st
156156
}
157157
}
158158
// Record the local and remote addresses from the actual socket.
159-
// For the local address, use
160-
// 1) the one returned by Getsockname, if that succeeds; or
161-
// 2) the one passed to us as the laddr parameter; or
162-
// 3) nil.
159+
// Get the local address by calling Getsockname.
163160
// For the remote address, use
164161
// 1) the one returned by the connect method, if any; or
165162
// 2) the one from Getpeername, if it succeeds; or
166163
// 3) the one passed to us as the raddr parameter.
167-
var laddrName Addr = laddr
168-
if lsa, err := syscall.Getsockname(fd.pfd.Sysfd); err == nil {
169-
laddrName = fd.addrFunc()(lsa)
170-
}
164+
lsa, _ = syscall.Getsockname(fd.pfd.Sysfd)
171165
if crsa != nil {
172-
fd.setAddr(laddrName, fd.addrFunc()(crsa))
166+
fd.setAddr(fd.addrFunc()(lsa), fd.addrFunc()(crsa))
173167
} else if rsa, _ = syscall.Getpeername(fd.pfd.Sysfd); rsa != nil {
174-
fd.setAddr(laddrName, fd.addrFunc()(rsa))
168+
fd.setAddr(fd.addrFunc()(lsa), fd.addrFunc()(rsa))
175169
} else {
176-
fd.setAddr(laddrName, raddr)
170+
fd.setAddr(fd.addrFunc()(lsa), raddr)
177171
}
178172
return nil
179173
}

0 commit comments

Comments
 (0)