Merge pull request #2235 from lucas-clemente/crypto-buffer-exceeded

use the CRYPTO_BUFFER_EXCEEDED error for crypto stream overflows
This commit is contained in:
Marten Seemann
2019-11-24 21:06:21 +07:00
committed by GitHub
3 changed files with 5 additions and 2 deletions

View File

@@ -69,7 +69,7 @@ func newCryptoStream() cryptoStream {
func (s *cryptoStreamImpl) HandleCryptoFrame(f *wire.CryptoFrame) error { func (s *cryptoStreamImpl) HandleCryptoFrame(f *wire.CryptoFrame) error {
highestOffset := f.Offset + protocol.ByteCount(len(f.Data)) highestOffset := f.Offset + protocol.ByteCount(len(f.Data))
if maxOffset := highestOffset; maxOffset > protocol.MaxCryptoStreamOffset { if maxOffset := highestOffset; maxOffset > protocol.MaxCryptoStreamOffset {
return fmt.Errorf("received invalid offset %d on crypto stream, maximum allowed %d", maxOffset, protocol.MaxCryptoStreamOffset) return qerr.Error(qerr.CryptoBufferExceeded, fmt.Sprintf("received invalid offset %d on crypto stream, maximum allowed %d", maxOffset, protocol.MaxCryptoStreamOffset))
} }
if s.finished { if s.finished {
if highestOffset > s.highestOffset { if highestOffset > s.highestOffset {

View File

@@ -55,7 +55,7 @@ var _ = Describe("Crypto Stream", func() {
Offset: protocol.MaxCryptoStreamOffset - 5, Offset: protocol.MaxCryptoStreamOffset - 5,
Data: []byte("foobar"), Data: []byte("foobar"),
}) })
Expect(err).To(MatchError(fmt.Sprintf("received invalid offset %d on crypto stream, maximum allowed %d", protocol.MaxCryptoStreamOffset+1, protocol.MaxCryptoStreamOffset))) Expect(err).To(MatchError(fmt.Sprintf("CRYPTO_BUFFER_EXCEEDED: received invalid offset %d on crypto stream, maximum allowed %d", protocol.MaxCryptoStreamOffset+1, protocol.MaxCryptoStreamOffset)))
}) })
It("handles messages split over multiple CRYPTO frames", func() { It("handles messages split over multiple CRYPTO frames", func() {

View File

@@ -23,6 +23,7 @@ const (
VersionNegotiationError ErrorCode = 0x9 VersionNegotiationError ErrorCode = 0x9
ProtocolViolation ErrorCode = 0xa ProtocolViolation ErrorCode = 0xa
InvalidMigration ErrorCode = 0xc InvalidMigration ErrorCode = 0xc
CryptoBufferExceeded ErrorCode = 0xd
) )
func (e ErrorCode) isCryptoError() bool { func (e ErrorCode) isCryptoError() bool {
@@ -71,6 +72,8 @@ func (e ErrorCode) String() string {
return "PROTOCOL_VIOLATION" return "PROTOCOL_VIOLATION"
case InvalidMigration: case InvalidMigration:
return "INVALID_MIGRATION" return "INVALID_MIGRATION"
case CryptoBufferExceeded:
return "CRYPTO_BUFFER_EXCEEDED"
default: default:
if e.isCryptoError() { if e.isCryptoError() {
return "CRYPTO_ERROR" return "CRYPTO_ERROR"