forked from quic-go/quic-go
@@ -38,6 +38,10 @@ func ParseConnectionCloseFrame(r *bytes.Reader) (*ConnectionCloseFrame, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if reasonPhraseLen > uint16(protocol.MaxPacketSize) {
|
||||
return nil, qerr.Error(qerr.InvalidConnectionCloseData, "reason phrase too long")
|
||||
}
|
||||
|
||||
reasonPhrase := make([]byte, reasonPhraseLen)
|
||||
if _, err := io.ReadFull(r, reasonPhrase); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -29,6 +29,12 @@ var _ = Describe("ConnectionCloseFrame", func() {
|
||||
Expect(frame.ReasonPhrase).To(BeEmpty())
|
||||
Expect(b.Len()).To(Equal(0))
|
||||
})
|
||||
|
||||
It("rejects long reason phrases", func() {
|
||||
b := bytes.NewReader([]byte{0x02, 0xAD, 0xFB, 0xCA, 0xDE, 0xff, 0xf})
|
||||
_, err := ParseConnectionCloseFrame(b)
|
||||
Expect(err).To(MatchError(qerr.Error(qerr.InvalidConnectionCloseData, "reason phrase too long")))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when writing", func() {
|
||||
|
||||
@@ -62,6 +62,10 @@ func ParseStreamFrame(r *bytes.Reader) (*StreamFrame, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if dataLen > uint16(protocol.MaxPacketSize) {
|
||||
return nil, qerr.Error(qerr.InvalidStreamData, "data len too large")
|
||||
}
|
||||
|
||||
if dataLen == 0 {
|
||||
// The rest of the packet is data
|
||||
frame.Data, err = ioutil.ReadAll(r)
|
||||
|
||||
@@ -47,6 +47,12 @@ var _ = Describe("StreamFrame", func() {
|
||||
_, err := ParseStreamFrame(b)
|
||||
Expect(err).To(MatchError(qerr.EmptyStreamFrameNoFin))
|
||||
})
|
||||
|
||||
It("rejects frames to too large dataLen", func() {
|
||||
b := bytes.NewReader([]byte{0xa0, 0x1, 0xff, 0xf})
|
||||
_, err := ParseStreamFrame(b)
|
||||
Expect(err).To(MatchError(qerr.Error(qerr.InvalidStreamData, "data len too large")))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when writing", func() {
|
||||
|
||||
Reference in New Issue
Block a user