Skip to content

Commit b6778c5

Browse files
ianlancetaylorgopherbot
authored andcommitted
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 <[email protected]> Commit-Queue: Ian Lance Taylor <[email protected]> Reviewed-by: Damien Neil <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
1 parent 7b3c380 commit b6778c5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/internal/poll/fd_unix.go

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package poll
88

99
import (
10+
"internal/itoa"
1011
"internal/syscall/unix"
1112
"io"
1213
"sync/atomic"
@@ -379,6 +380,14 @@ func (fd *FD) Write(p []byte) (int, error) {
379380
}
380381
n, err := ignoringEINTRIO(syscall.Write, fd.Sysfd, p[nn:max])
381382
if n > 0 {
383+
if n > max-nn {
384+
// This can reportedly happen when using
385+
// some VPN software. Issue #61060.
386+
// If we don't check this we will panic
387+
// with slice bounds out of range.
388+
// Use a more informative panic.
389+
panic("invalid return from write: got " + itoa.Itoa(n) + " from a write of " + itoa.Itoa(max-nn))
390+
}
382391
nn += n
383392
}
384393
if nn == len(p) {

0 commit comments

Comments
 (0)