aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorqmuntal <quimmuntal@gmail.com>2026-01-08 15:50:15 +0100
committerQuim Muntal <quimmuntal@gmail.com>2026-01-12 11:53:11 -0800
commitcbe153806e67a16e362a1cdbbf1741d4ce82e98a (patch)
treed79fd08a98364dd2b52961388168fc805ab54bd1
parent30d0b4026410da3486ba841bb7f13c1d9074e91d (diff)
downloadgo-cbe153806e67a16e362a1cdbbf1741d4ce82e98a.tar.xz
net: fix socket duplication error handling on Windows
Calls to dupSocket may fail, but the error is not properly handled because the surrounding code incorrectly checks for nil error instead of non-nil error. I'm not aware of any code paths that would trigger this error, and I haven't been able to create a test case that does so, but this change fixes the error handling to correctly propagate any errors from dupSocket. Change-Id: I5ffd3cbe8ed58a83634f3b97c0878a7c73e0505e Reviewed-on: https://go-review.googlesource.com/c/go/+/734821 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
-rw-r--r--src/net/fd_windows.go2
-rw-r--r--src/net/file_windows.go2
2 files changed, 2 insertions, 2 deletions
diff --git a/src/net/fd_windows.go b/src/net/fd_windows.go
index 52985be8e6..c28ce045c4 100644
--- a/src/net/fd_windows.go
+++ b/src/net/fd_windows.go
@@ -248,7 +248,7 @@ func (fd *netFD) dup() (*os.File, error) {
err := fd.pfd.RawControl(func(fd uintptr) {
h, syserr = dupSocket(syscall.Handle(fd))
})
- if err != nil {
+ if err == nil {
err = syserr
}
if err != nil {
diff --git a/src/net/file_windows.go b/src/net/file_windows.go
index b4eb00e564..6a6305035a 100644
--- a/src/net/file_windows.go
+++ b/src/net/file_windows.go
@@ -39,7 +39,7 @@ func dupFileSocket(f *os.File) (syscall.Handle, error) {
err = sc.Control(func(fd uintptr) {
h, syserr = dupSocket(syscall.Handle(fd))
})
- if err != nil {
+ if err == nil {
err = syserr
}
if err != nil {