mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
parent
0a825a397d
commit
841421ef7a
4 changed files with 4 additions and 21 deletions
|
@ -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())
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue