diff options
author | Tamir Duberstein <tamird@google.com> | 2021-01-22 12:24:20 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-01-22 12:26:09 -0800 |
commit | 6c0e1d9cfe6adbfbb32e7020d6426608ac63ad37 (patch) | |
tree | 3ddb770b9965ccfcdb6ecb73062e2d466c379439 /pkg/tcpip/transport/tcp/endpoint.go | |
parent | 527ef5fc0307102fa7cc0b32bcc2eb8cca3e21a8 (diff) |
Define tcpip.Payloader in terms of io.Reader
Fixes #1509.
PiperOrigin-RevId: 353295589
Diffstat (limited to 'pkg/tcpip/transport/tcp/endpoint.go')
-rw-r--r-- | pkg/tcpip/transport/tcp/endpoint.go | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/pkg/tcpip/transport/tcp/endpoint.go b/pkg/tcpip/transport/tcp/endpoint.go index ea509ac73..8d27d43c2 100644 --- a/pkg/tcpip/transport/tcp/endpoint.go +++ b/pkg/tcpip/transport/tcp/endpoint.go @@ -1534,14 +1534,19 @@ func (e *endpoint) Write(p tcpip.Payloader, opts tcpip.WriteOptions) (int64, *tc } // Fetch data. - v, perr := p.Payload(avail) - if perr != nil || len(v) == 0 { - // Note that perr may be nil if len(v) == 0. + if l := p.Len(); l < avail { + avail = l + } + if avail == 0 { + return 0, nil + } + v := make([]byte, avail) + if _, err := io.ReadFull(p, v); err != nil { if opts.Atomic { e.sndBufMu.Unlock() e.UnlockUser() } - return 0, perr + return 0, tcpip.ErrBadBuffer } if !opts.Atomic { |