forked from quic-go/quic-go
Merge pull request #889 from lucas-clemente/fix-connection-close-parsing
fix parsing of long reason phrases in CONNECTION_CLOSE frames
This commit is contained in:
@@ -38,12 +38,16 @@ func ParseConnectionCloseFrame(r *bytes.Reader, version protocol.VersionNumber)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if reasonPhraseLen > uint16(protocol.MaxPacketSize) {
|
||||
return nil, qerr.Error(qerr.InvalidConnectionCloseData, "reason phrase too long")
|
||||
// shortcut to prevent the unneccessary allocation of dataLen bytes
|
||||
// if the dataLen is larger than the remaining length of the packet
|
||||
// reading the whole reason phrase would result in EOF when attempting to READ
|
||||
if int(reasonPhraseLen) > r.Len() {
|
||||
return nil, io.EOF
|
||||
}
|
||||
|
||||
reasonPhrase := make([]byte, reasonPhraseLen)
|
||||
if _, err := io.ReadFull(r, reasonPhrase); err != nil {
|
||||
// this should never happen, since we already checked the reasonPhraseLen earlier
|
||||
return nil, err
|
||||
}
|
||||
frame.ReasonPhrase = string(reasonPhrase)
|
||||
|
||||
@@ -2,6 +2,7 @@ package wire
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||
@@ -32,7 +33,7 @@ var _ = Describe("ConnectionCloseFrame", func() {
|
||||
0x0, 0xff, // reason phrase length
|
||||
})
|
||||
_, err := ParseConnectionCloseFrame(b, versionLittleEndian)
|
||||
Expect(err).To(MatchError(qerr.Error(qerr.InvalidConnectionCloseData, "reason phrase too long")))
|
||||
Expect(err).To(MatchError(io.EOF))
|
||||
})
|
||||
|
||||
It("errors on EOFs", func() {
|
||||
@@ -70,7 +71,7 @@ var _ = Describe("ConnectionCloseFrame", func() {
|
||||
0xff, 0x0, // reason phrase length
|
||||
})
|
||||
_, err := ParseConnectionCloseFrame(b, versionBigEndian)
|
||||
Expect(err).To(MatchError(qerr.Error(qerr.InvalidConnectionCloseData, "reason phrase too long")))
|
||||
Expect(err).To(MatchError(io.EOF))
|
||||
})
|
||||
|
||||
It("errors on EOFs", func() {
|
||||
|
||||
Reference in New Issue
Block a user