From 49ccd0bb014377a6d6b33683eccdf22c4ef90c7d Mon Sep 17 00:00:00 2001 From: Lucas Clemente Date: Thu, 14 Apr 2016 16:37:12 +0200 Subject: [PATCH] don't accept 0-byte connection IDs since we are a server --- public_header.go | 3 +++ public_header_test.go | 14 ++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/public_header.go b/public_header.go index 1a994c15..416f2e6b 100644 --- a/public_header.go +++ b/public_header.go @@ -75,6 +75,9 @@ func ParsePublicHeader(b io.ByteReader) (*PublicHeader, error) { if err != nil { return nil, err } + if header.ConnectionID == 0 { + return nil, errors.New("PublicHeader: connection ID cannot be 0") + } // Version (optional) diff --git a/public_header_test.go b/public_header_test.go index 0172eebf..60112185 100644 --- a/public_header_test.go +++ b/public_header_test.go @@ -41,16 +41,14 @@ var _ = Describe("Public Header", func() { Expect(b.Len()).To(BeZero()) }) - It("accepts 0-byte connection ID", func() { + It("does not accept 0-byte connection ID", func() { b := bytes.NewReader([]byte{0x00, 0x01}) - publicHeader, err := ParsePublicHeader(b) - Expect(err).ToNot(HaveOccurred()) - Expect(publicHeader.VersionFlag).To(BeFalse()) - Expect(b.Len()).To(BeZero()) + _, err := ParsePublicHeader(b) + Expect(err).To(HaveOccurred()) }) It("accepts 2-byte packet numbers", func() { - b := bytes.NewReader([]byte{0x10, 0xde, 0xca}) + b := bytes.NewReader([]byte{0x14, 0x01, 0xde, 0xca}) publicHeader, err := ParsePublicHeader(b) Expect(err).ToNot(HaveOccurred()) Expect(publicHeader.PacketNumber).To(Equal(protocol.PacketNumber(0xcade))) @@ -58,7 +56,7 @@ var _ = Describe("Public Header", func() { }) It("accepts 4-byte packet numbers", func() { - b := bytes.NewReader([]byte{0x20, 0xad, 0xfb, 0xca, 0xde}) + b := bytes.NewReader([]byte{0x24, 0x01, 0xad, 0xfb, 0xca, 0xde}) publicHeader, err := ParsePublicHeader(b) Expect(err).ToNot(HaveOccurred()) Expect(publicHeader.PacketNumber).To(Equal(protocol.PacketNumber(0xdecafbad))) @@ -66,7 +64,7 @@ var _ = Describe("Public Header", func() { }) It("accepts 6-byte packet numbers", func() { - b := bytes.NewReader([]byte{0x30, 0x23, 0x42, 0xad, 0xfb, 0xca, 0xde}) + b := bytes.NewReader([]byte{0x34, 0x01, 0x23, 0x42, 0xad, 0xfb, 0xca, 0xde}) publicHeader, err := ParsePublicHeader(b) Expect(err).ToNot(HaveOccurred()) Expect(publicHeader.PacketNumber).To(Equal(protocol.PacketNumber(0xdecafbad4223)))