Skip to content

Commit

Permalink
add an overflow check to the STREAMS_BLOCKED frame parser
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Nov 8, 2019
1 parent 1e7c784 commit 5d54a11
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/wire/streams_blocked_frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
28 changes: 28 additions & 0 deletions internal/wire/streams_blocked_frame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package wire

import (
"bytes"
"fmt"
"io"

"github.com/lucas-clemente/quic-go/internal/protocol"
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 5d54a11

Please sign in to comment.