summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/socket
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-01-16 00:07:58 +0000
committergVisor bot <gvisor-bot@google.com>2021-01-16 00:07:58 +0000
commit06bcbc23fd8a186b0314fc8aae50545a972d7f5c (patch)
tree082d2058c07b5b9cb3e31e515519dd21d2269734 /pkg/sentry/socket
parent0b4604d503bfac4dfccd6f0b7e34b55dc2c9e36d (diff)
parent12d9790833cc2f6a9b197066a5ecbeb434f74164 (diff)
Merge release-20210112.0-37-g12d979083 (automated)
Diffstat (limited to 'pkg/sentry/socket')
-rw-r--r--pkg/sentry/socket/netstack/netstack.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/pkg/sentry/socket/netstack/netstack.go b/pkg/sentry/socket/netstack/netstack.go
index 03749a8bf..22e128b96 100644
--- a/pkg/sentry/socket/netstack/netstack.go
+++ b/pkg/sentry/socket/netstack/netstack.go
@@ -425,8 +425,13 @@ func (s *SocketOperations) WriteTo(ctx context.Context, _ *fs.File, dst io.Write
s.readMu.Lock()
defer s.readMu.Unlock()
+ w := tcpip.LimitedWriter{
+ W: dst,
+ N: count,
+ }
+
// This may return a blocking error.
- res, err := s.Endpoint.Read(dst, int(count), tcpip.ReadOptions{
+ res, err := s.Endpoint.Read(&w, tcpip.ReadOptions{
Peek: dup,
})
if err != nil {
@@ -2579,7 +2584,10 @@ func (s *socketOpsCommon) nonBlockingRead(ctx context.Context, dst usermem.IOSeq
// caller-supplied buffer.
var w io.Writer
if !isPacket && trunc {
- w = ioutil.Discard
+ w = &tcpip.LimitedWriter{
+ W: ioutil.Discard,
+ N: dst.NumBytes(),
+ }
} else {
w = dst.Writer(ctx)
}
@@ -2587,7 +2595,10 @@ func (s *socketOpsCommon) nonBlockingRead(ctx context.Context, dst usermem.IOSeq
s.readMu.Lock()
defer s.readMu.Unlock()
- res, err := s.Endpoint.Read(w, int(dst.NumBytes()), readOptions)
+ res, err := s.Endpoint.Read(w, readOptions)
+ if err == tcpip.ErrBadBuffer && dst.NumBytes() == 0 {
+ err = nil
+ }
if err != nil {
return 0, 0, nil, 0, socket.ControlMessages{}, syserr.TranslateNetstackError(err)
}