Fix error handling for bad message sizes.

The message size check is legitimate: the size must be negotiated, which
relies on the fixed message limit up front. Sending a message larger than
that indicates that the connection is out of sync and is considered a
socket error (disconnect).

Similarly, sending a size that is too small indicates that the stream is
out-of-sync or invalid.

PiperOrigin-RevId: 207996551
Change-Id: Icd8b513d5307e9d5953dbb957ee70ceea111098d
This commit is contained in:
Adin Scannell
2018-08-08 22:23:47 -07:00
committed by Shentubot
parent ea1e39a314
commit 48b5b35b2b
2 changed files with 4 additions and 4 deletions
+2 -2
View File
@@ -206,11 +206,11 @@ func recv(s *unet.Socket, msize uint32, lookup lookupTagAndType) (Tag, message,
// The message is too small.
//
// See above: it's probably screwed.
return NoTag, nil, ErrNoValidMessage
return NoTag, nil, ErrSocket{ErrNoValidMessage}
}
if size > maximumLength || size > msize {
// The message is too big.
return NoTag, nil, &ErrMessageTooLarge{size, msize}
return NoTag, nil, ErrSocket{&ErrMessageTooLarge{size, msize}}
}
remaining := size - headerLength
+2 -2
View File
@@ -73,8 +73,8 @@ func TestRecvOverrun(t *testing.T) {
t.Fatalf("send got err %v expected nil", err)
}
if _, _, err := recv(server, maximumLength, messageByType); err != ErrNoValidMessage {
t.Fatalf("recv got err %v expected ErrNoValidMessage", err)
if _, _, err := recv(server, maximumLength, messageByType); err == nil {
t.Fatalf("recv got err %v expected ErrSocket{ErrNoValidMessage}", err)
}
}