summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorTing-Yu Wang <anivia@google.com>2021-01-15 12:48:58 -0800
committergVisor bot <gvisor-bot@google.com>2021-01-15 12:51:08 -0800
commitf1420cf48418c01694eaf3110ac411915b217d36 (patch)
tree0c1bfcef59170f85100c4f4c4a0e2a602d699064 /pkg
parentf7f66c8c6cb5284afe11f4571568866e3c605466 (diff)
Add sanity check on return values from Write
io.Writer.Write requires err to be non-nil if n < len(v). We could allow this but it will be irreversible if users depend on this behavior. Ported the test that discovered this. PiperOrigin-RevId: 352065946
Diffstat (limited to 'pkg')
-rw-r--r--pkg/tcpip/buffer/view.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/pkg/tcpip/buffer/view.go b/pkg/tcpip/buffer/view.go
index 5dd1b1b6b..09d3dac66 100644
--- a/pkg/tcpip/buffer/view.go
+++ b/pkg/tcpip/buffer/view.go
@@ -17,6 +17,7 @@ package buffer
import (
"bytes"
+ "fmt"
"io"
)
@@ -167,6 +168,9 @@ func (vv *VectorisedView) ReadTo(dst io.Writer, count int, peek bool) (int, erro
if err != nil {
break
}
+ if n != len(v) {
+ panic(fmt.Sprintf("io.Writer.Write succeeded with incomplete write: %d != %d", n, len(v)))
+ }
}
if !peek {
vv.TrimFront(done)