From 693ef293acc47cf10136c0bd590ee44bd3aca742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 21 Sep 2022 17:05:13 +0800 Subject: [PATCH] Update buffer usage --- common/mux/client.go | 5 +---- common/mux/service.go | 7 ------- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 4 insertions(+), 14 deletions(-) diff --git a/common/mux/client.go b/common/mux/client.go index 3e83ccb0..c1d3daa3 100644 --- a/common/mux/client.go +++ b/common/mux/client.go @@ -466,10 +466,7 @@ func (c *ClientPacketAddrConn) ReadPacket(buffer *buf.Buffer) (destination M.Soc if err != nil { return } - if buffer.FreeLen() < int(length) { - return destination, io.ErrShortBuffer - } - _, err = io.ReadFull(c.ExtendedConn, buffer.Extend(int(length))) + _, err = buffer.ReadFullFrom(c.ExtendedConn, int(length)) return } diff --git a/common/mux/service.go b/common/mux/service.go index f89796dc..de9a498a 100644 --- a/common/mux/service.go +++ b/common/mux/service.go @@ -3,7 +3,6 @@ package mux import ( "context" "encoding/binary" - "io" "net" "github.com/sagernet/sing-box/adapter" @@ -158,9 +157,6 @@ func (c *ServerPacketConn) ReadPacket(buffer *buf.Buffer) (destination M.Socksad if err != nil { return } - if buffer.FreeLen() < int(length) { - return destination, io.ErrShortBuffer - } _, err = buffer.ReadFullFrom(c.ExtendedConn, int(length)) if err != nil { return @@ -223,9 +219,6 @@ func (c *ServerPacketAddrConn) ReadPacket(buffer *buf.Buffer) (destination M.Soc if err != nil { return } - if buffer.FreeLen() < int(length) { - return destination, io.ErrShortBuffer - } _, err = buffer.ReadFullFrom(c.ExtendedConn, int(length)) if err != nil { return diff --git a/go.mod b/go.mod index 358c6bc5..ce83aafd 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/pires/go-proxyproto v0.6.2 github.com/refraction-networking/utls v1.1.2 github.com/sagernet/quic-go v0.0.0-20220818150011-de611ab3e2bb - github.com/sagernet/sing v0.0.0-20220916071326-834794b006ea + github.com/sagernet/sing v0.0.0-20220921090219-b2828dac5f86 github.com/sagernet/sing-dns v0.0.0-20220915084601-812e0864b45b github.com/sagernet/sing-shadowsocks v0.0.0-20220819002358-7461bb09a8f6 github.com/sagernet/sing-tun v0.0.0-20220916073459-0032242c9617 diff --git a/go.sum b/go.sum index c18c0d72..28a5e1cd 100644 --- a/go.sum +++ b/go.sum @@ -145,8 +145,8 @@ github.com/sagernet/quic-go v0.0.0-20220818150011-de611ab3e2bb h1:wc0yQ+SBn4TaTY github.com/sagernet/quic-go v0.0.0-20220818150011-de611ab3e2bb/go.mod h1:MIccjRKnPTjWwAOpl+AUGWOkzyTd9tERytudxu+1ra4= github.com/sagernet/sing v0.0.0-20220812082120-05f9836bff8f/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY= github.com/sagernet/sing v0.0.0-20220817130738-ce854cda8522/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY= -github.com/sagernet/sing v0.0.0-20220916071326-834794b006ea h1:ZAWvZdeByPBBz3Vs+w3Erbh+DDo7D4biokoPhXl0nNU= -github.com/sagernet/sing v0.0.0-20220916071326-834794b006ea/go.mod h1:x3NHUeJBQwV75L51zwmLKQdLtRvR+M4PmXkfQtU1vIY= +github.com/sagernet/sing v0.0.0-20220921090219-b2828dac5f86 h1:cjEloP/20kV1p6RBNvNQWaOMulgmlwHUyB9S7KikZzw= +github.com/sagernet/sing v0.0.0-20220921090219-b2828dac5f86/go.mod h1:x3NHUeJBQwV75L51zwmLKQdLtRvR+M4PmXkfQtU1vIY= github.com/sagernet/sing-dns v0.0.0-20220915084601-812e0864b45b h1:cXCMNJ9heZ+c6l+qUcku60x9KyXo4SOAaJfg/6spOmU= github.com/sagernet/sing-dns v0.0.0-20220915084601-812e0864b45b/go.mod h1:SrvWLfOSlnFmH32CWXicfilAGgIXR0VjrH6yRbuXYww= github.com/sagernet/sing-shadowsocks v0.0.0-20220819002358-7461bb09a8f6 h1:JJfDeYYhWunvtxsU/mOVNTmFQmnzGx9dY034qG6G3g4=