remove ineffective check for too large packets

closes #468
This commit is contained in:
Marten Seemann 2017-03-15 09:30:06 +07:00
parent 0a825a397d
commit 841421ef7a
No known key found for this signature in database
GPG key ID: 3603F40B121FCDEA
4 changed files with 4 additions and 21 deletions

View file

@ -116,7 +116,8 @@ func (c *client) listen() {
var addr net.Addr
data := getPacketBuffer()
data = data[:protocol.MaxReceivePacketSize]
// The packet size should not exceed protocol.MaxReceivePacketSize bytes
// If it does, we only read a truncated packet, which will then end up undecryptable
n, addr, err = c.conn.Read(data)
if err != nil {
if !strings.HasSuffix(err.Error(), "use of closed network connection") {
@ -141,14 +142,9 @@ func (c *client) listen() {
}
func (c *client) handlePacket(remoteAddr net.Addr, packet []byte) error {
if protocol.ByteCount(len(packet)) > protocol.MaxReceivePacketSize {
return qerr.PacketTooLarge
}
rcvTime := time.Now()
r := bytes.NewReader(packet)
hdr, err := ParsePublicHeader(r, protocol.PerspectiveServer)
if err != nil {
return qerr.Error(qerr.InvalidPacketHeader, err.Error())

View file

@ -146,11 +146,6 @@ var _ = Describe("Client", func() {
})
Context("handling packets", func() {
It("errors on too large packets", func() {
err := cl.handlePacket(nil, bytes.Repeat([]byte{'f'}, int(protocol.MaxReceivePacketSize+1)))
Expect(err).To(MatchError(qerr.PacketTooLarge))
})
It("handles packets", func() {
ph := PublicHeader{
PacketNumber: 1,

View file

@ -84,6 +84,8 @@ func (s *server) Serve() error {
for {
data := getPacketBuffer()
data = data[:protocol.MaxReceivePacketSize]
// The packet size should not exceed protocol.MaxReceivePacketSize bytes
// If it does, we only read a truncated packet, which will then end up undecryptable
n, remoteAddr, err := s.conn.ReadFrom(data)
if err != nil {
if strings.HasSuffix(err.Error(), "use of closed network connection") {
@ -122,14 +124,9 @@ func (s *server) Addr() net.Addr {
}
func (s *server) handlePacket(pconn net.PacketConn, remoteAddr net.Addr, packet []byte) error {
if protocol.ByteCount(len(packet)) > protocol.MaxReceivePacketSize {
return qerr.PacketTooLarge
}
rcvTime := time.Now()
r := bytes.NewReader(packet)
hdr, err := ParsePublicHeader(r, protocol.PerspectiveClient)
if err != nil {
return qerr.Error(qerr.InvalidPacketHeader, err.Error())

View file

@ -255,11 +255,6 @@ var _ = Describe("Server", func() {
Expect(err.(*qerr.QuicError).ErrorCode).To(Equal(qerr.InvalidPacketHeader))
})
It("errors on large packets", func() {
err := serv.handlePacket(nil, nil, bytes.Repeat([]byte{'a'}, int(protocol.MaxReceivePacketSize)+1))
Expect(err).To(MatchError(qerr.PacketTooLarge))
})
It("ignores public resets for unknown connections", func() {
err := serv.handlePacket(nil, nil, writePublicReset(999, 1, 1337))
Expect(err).ToNot(HaveOccurred())