]> Cypherpunks repositories - gostls13.git/commitdiff
internal/poll: better panic for invalid write return value
authorIan Lance Taylor <iant@golang.org>
Wed, 10 Apr 2024 16:59:20 +0000 (09:59 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 11 Apr 2024 00:32:52 +0000 (00:32 +0000)
For #61060

Change-Id: I13cd73b4062cb7bd248d2a4afae06dfa29ac0203
Reviewed-on: https://go-review.googlesource.com/c/go/+/577955
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>

src/internal/poll/fd_unix.go

index 61c2338305ada4b2399acf3775268c0c3f3969f0..5797ab65bb6bd5e49f89c761b801db6eec4a2a78 100644 (file)
@@ -7,6 +7,7 @@
 package poll
 
 import (
+       "internal/itoa"
        "internal/syscall/unix"
        "io"
        "sync/atomic"
@@ -379,6 +380,14 @@ func (fd *FD) Write(p []byte) (int, error) {
                }
                n, err := ignoringEINTRIO(syscall.Write, fd.Sysfd, p[nn:max])
                if n > 0 {
+                       if n > max-nn {
+                               // This can reportedly happen when using
+                               // some VPN software. Issue #61060.
+                               // If we don't check this we will panic
+                               // with slice bounds out of range.
+                               // Use a more informative panic.
+                               panic("invalid return from write: got " + itoa.Itoa(n) + " from a write of " + itoa.Itoa(max-nn))
+                       }
                        nn += n
                }
                if nn == len(p) {