include the packet size in the error when packing a too large packet

This commit is contained in:
Marten Seemann 2018-02-05 09:17:20 +08:00
parent 30851b9a3b
commit 38c420a35b
2 changed files with 5 additions and 3 deletions

View file

@ -366,8 +366,9 @@ func (p *packetPacker) writeAndSealPacket(
buffer.Write(bytes.Repeat([]byte{0}, paddingLen))
}
}
if protocol.ByteCount(buffer.Len()+sealer.Overhead()) > protocol.MaxPacketSize {
return nil, errors.New("PacketPacker BUG: packet too large")
if size := protocol.ByteCount(buffer.Len() + sealer.Overhead()); size > protocol.MaxPacketSize {
return nil, fmt.Errorf("PacketPacker BUG: packet too large (%d bytes, allowed %d bytes)", size, protocol.MaxPacketSize)
}
raw = raw[0:buffer.Len()]

View file

@ -679,7 +679,8 @@ var _ = Describe("Packet packer", func() {
},
}
_, err := packer.PackHandshakeRetransmission(packet)
Expect(err).To(MatchError("PacketPacker BUG: packet too large"))
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("PacketPacker BUG: packet too large"))
})
It("pads Initial packets to the required minimum packet size", func() {