From 2c6d23952518cc633fb219b29f49de6c6182c48e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 8 Aug 2022 08:09:17 +0800 Subject: [PATCH] Fix mux overflow --- common/mux/service.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/common/mux/service.go b/common/mux/service.go index acb8ab9f..64f45b81 100644 --- a/common/mux/service.go +++ b/common/mux/service.go @@ -3,6 +3,7 @@ package mux import ( "context" "encoding/binary" + "io" "net" "github.com/sagernet/sing-box/adapter" @@ -156,6 +157,9 @@ 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 @@ -218,6 +222,9 @@ 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