From: Ian Lance Taylor Date: Wed, 10 Apr 2024 16:59:20 +0000 (-0700) Subject: internal/poll: better panic for invalid write return value X-Git-Tag: go1.23rc1~647 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b6778c5230d554c1ba1a69b104513021467d32b2;p=gostls13.git internal/poll: better panic for invalid write return value For #61060 Change-Id: I13cd73b4062cb7bd248d2a4afae06dfa29ac0203 Reviewed-on: https://go-review.googlesource.com/c/go/+/577955 LUCI-TryBot-Result: Go LUCI Commit-Queue: Ian Lance Taylor Reviewed-by: Damien Neil Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor --- diff --git a/src/internal/poll/fd_unix.go b/src/internal/poll/fd_unix.go index 61c2338305..5797ab65bb 100644 --- a/src/internal/poll/fd_unix.go +++ b/src/internal/poll/fd_unix.go @@ -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) {