From 77d2f9edd7c3badb4738abdae5bda16c29ea287a Mon Sep 17 00:00:00 2001 From: MP <112455607+asiaqa@users.noreply.github.com> Date: Tue, 17 Jan 2023 11:18:58 +0800 Subject: [PATCH] Revise the Code per XTLS#1515 (#1536) * Use buf.FromBytes(make([]byte, 0, buf.Size)) to create `first` Fixes https://github.com/XTLS/Xray-core/issues/1515 * Update server.go * Update inbound.go Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com> --- proxy/trojan/server.go | 5 ++--- proxy/vless/inbound/inbound.go | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/proxy/trojan/server.go b/proxy/trojan/server.go index 618fbe10..6309bbc6 100644 --- a/proxy/trojan/server.go +++ b/proxy/trojan/server.go @@ -155,9 +155,8 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con return newError("unable to set read deadline").Base(err).AtWarning() } - first := buf.New() - defer first.Release() - + first := buf.FromBytes(make([]byte, buf.Size)) + first.Clear() firstLen, err := first.ReadFrom(conn) if err != nil { return newError("failed to read first request").Base(err) diff --git a/proxy/vless/inbound/inbound.go b/proxy/vless/inbound/inbound.go index b623fe6e..86b09e04 100644 --- a/proxy/vless/inbound/inbound.go +++ b/proxy/vless/inbound/inbound.go @@ -188,9 +188,8 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s return newError("unable to set read deadline").Base(err).AtWarning() } - first := buf.New() - defer first.Release() - + first := buf.FromBytes(make([]byte, buf.Size)) + first.Clear() firstLen, _ := first.ReadFrom(connection) newError("firstLen = ", firstLen).AtInfo().WriteToLog(sid)