add an overflow check to the STREAMS_BLOCKED frame parser

This commit is contained in:
Marten Seemann
2019-11-08 11:50:22 +07:00
parent 1e7c7842b9
commit 5d54a11e04
2 changed files with 32 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package wire
import (
"bytes"
"fmt"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/utils"
@@ -31,7 +32,9 @@ func parseStreamsBlockedFrame(r *bytes.Reader, _ protocol.VersionNumber) (*Strea
return nil, err
}
f.StreamLimit = protocol.StreamNum(streamLimit)
if f.StreamLimit > protocol.MaxStreamCount {
return nil, fmt.Errorf("%d exceeds the maximum stream count", f.StreamLimit)
}
return f, nil
}

View File

@@ -2,6 +2,7 @@ package wire
import (
"bytes"
"fmt"
"io"
"github.com/lucas-clemente/quic-go/internal/protocol"
@@ -44,6 +45,33 @@ var _ = Describe("STREAMS_BLOCKED frame", func() {
Expect(err).To(MatchError(io.EOF))
}
})
for _, t := range []protocol.StreamType{protocol.StreamTypeUni, protocol.StreamTypeBidi} {
streamType := t
It("accepts a frame containing the maximum stream count", func() {
f := &StreamsBlockedFrame{
Type: streamType,
StreamLimit: protocol.MaxStreamCount,
}
b := &bytes.Buffer{}
Expect(f.Write(b, protocol.VersionWhatever)).To(Succeed())
frame, err := parseStreamsBlockedFrame(bytes.NewReader(b.Bytes()), protocol.VersionWhatever)
Expect(err).ToNot(HaveOccurred())
Expect(frame).To(Equal(f))
})
It("errors when receiving a too large stream count", func() {
f := &StreamsBlockedFrame{
Type: streamType,
StreamLimit: protocol.MaxStreamCount + 1,
}
b := &bytes.Buffer{}
Expect(f.Write(b, protocol.VersionWhatever)).To(Succeed())
_, err := parseStreamsBlockedFrame(bytes.NewReader(b.Bytes()), protocol.VersionWhatever)
Expect(err).To(MatchError(fmt.Sprintf("%d exceeds the maximum stream count", protocol.MaxStreamCount+1)))
})
}
})
Context("writing", func() {