summaryrefslogtreecommitdiffhomepage
path: root/pkg/p9/messages.go
diff options
context:
space:
mode:
authorUros Prestor <urosp@google.com>2020-04-02 22:01:57 -0700
committergVisor bot <gvisor-bot@google.com>2020-04-02 22:03:20 -0700
commitd151693530db68db43188ce0fbc9f81aa5f27e2e (patch)
tree1f721fd8660b0a48141ee1cf721bdebaa48bf2b0 /pkg/p9/messages.go
parentdd3bc499970c22ebbd270030b4564e6b8e4e929e (diff)
Avoid sending a partial dirent when the Rreaddir response exceeds message limit.
PiperOrigin-RevId: 304542967
Diffstat (limited to 'pkg/p9/messages.go')
-rw-r--r--pkg/p9/messages.go14
1 files changed, 6 insertions, 8 deletions
diff --git a/pkg/p9/messages.go b/pkg/p9/messages.go
index 3863ad1f5..57b89ad7d 100644
--- a/pkg/p9/messages.go
+++ b/pkg/p9/messages.go
@@ -1926,19 +1926,17 @@ func (r *Rreaddir) decode(b *buffer) {
// encode implements encoder.encode.
func (r *Rreaddir) encode(b *buffer) {
entriesBuf := buffer{}
+ payloadSize := 0
for _, d := range r.Entries {
d.encode(&entriesBuf)
- if len(entriesBuf.data) >= int(r.Count) {
+ if len(entriesBuf.data) > int(r.Count) {
break
}
+ payloadSize = len(entriesBuf.data)
}
- if len(entriesBuf.data) < int(r.Count) {
- r.Count = uint32(len(entriesBuf.data))
- r.payload = entriesBuf.data
- } else {
- r.payload = entriesBuf.data[:r.Count]
- }
- b.Write32(uint32(r.Count))
+ r.Count = uint32(payloadSize)
+ r.payload = entriesBuf.data[:payloadSize]
+ b.Write32(r.Count)
}
// Type implements message.Type.