From ca5a8d079242e1214f6d577fc9de3b5ae35009b8 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sat, 16 Sep 2017 13:53:42 +0700 Subject: [PATCH] reject packets with truncated connection ID, if truncation was disabled --- client.go | 4 ++++ client_test.go | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 8770fe0f9..6c44cce30 100644 --- a/client.go +++ b/client.go @@ -253,6 +253,10 @@ func (c *client) handlePacket(remoteAddr net.Addr, packet []byte) { // drop this packet if we can't parse the Public Header return } + // reject packets with truncated connection id if we didn't request truncation + if hdr.TruncateConnectionID && !c.config.RequestConnectionIDTruncation { + return + } hdr.Raw = packet[:len(packet)-r.Len()] c.mutex.Lock() diff --git a/client_test.go b/client_test.go index f8fed2890..8403101af 100644 --- a/client_test.go +++ b/client_test.go @@ -423,7 +423,21 @@ var _ = Describe("Client", func() { It("ignores packets with an invalid public header", func() { cl.handlePacket(addr, []byte("invalid packet")) - Expect(cl.session.(*mockSession).closed).To(BeFalse()) + Expect(sess.packetCount).To(BeZero()) + Expect(sess.closed).To(BeFalse()) + }) + + It("ignores packets without connection id, if it didn't request connection id trunctation", func() { + cl.config.RequestConnectionIDTruncation = false + buf := &bytes.Buffer{} + (&wire.PublicHeader{ + TruncateConnectionID: true, + PacketNumber: 1, + PacketNumberLen: 1, + }).Write(buf, protocol.VersionWhatever, protocol.PerspectiveServer) + cl.handlePacket(addr, buf.Bytes()) + Expect(sess.packetCount).To(BeZero()) + Expect(sess.closed).To(BeFalse()) }) It("creates new sessions with the right parameters", func(done Done) {