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
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if reasonPhraseLen > uint16(protocol.MaxPacketSize) {
|
// shortcut to prevent the unneccessary allocation of dataLen bytes
|
||||||
return nil, qerr.Error(qerr.InvalidConnectionCloseData, "reason phrase too long")
|
// 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)
|
reasonPhrase := make([]byte, reasonPhraseLen)
|
||||||
if _, err := io.ReadFull(r, reasonPhrase); err != nil {
|
if _, err := io.ReadFull(r, reasonPhrase); err != nil {
|
||||||
|
// this should never happen, since we already checked the reasonPhraseLen earlier
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
frame.ReasonPhrase = string(reasonPhrase)
|
frame.ReasonPhrase = string(reasonPhrase)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package wire
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||||
@@ -32,7 +33,7 @@ var _ = Describe("ConnectionCloseFrame", func() {
|
|||||||
0x0, 0xff, // reason phrase length
|
0x0, 0xff, // reason phrase length
|
||||||
})
|
})
|
||||||
_, err := ParseConnectionCloseFrame(b, versionLittleEndian)
|
_, 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() {
|
It("errors on EOFs", func() {
|
||||||
@@ -70,7 +71,7 @@ var _ = Describe("ConnectionCloseFrame", func() {
|
|||||||
0xff, 0x0, // reason phrase length
|
0xff, 0x0, // reason phrase length
|
||||||
})
|
})
|
||||||
_, err := ParseConnectionCloseFrame(b, versionBigEndian)
|
_, 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() {
|
It("errors on EOFs", func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user