From 1d450cfbd22a256bf6e411fccee477c0716505a8 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Mon, 13 May 2024 23:14:29 -0400 Subject: [PATCH] Fix nil in inbound handler --- proxy/vless/encoding/encoding.go | 8 ++++---- proxy/vless/inbound/inbound.go | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/proxy/vless/encoding/encoding.go b/proxy/vless/encoding/encoding.go index 2976be74..9bfea829 100644 --- a/proxy/vless/encoding/encoding.go +++ b/proxy/vless/encoding/encoding.go @@ -179,12 +179,12 @@ func XtlsRead(reader buf.Reader, writer buf.Writer, timer signal.ActivityUpdater for { if trafficState.ReaderSwitchToDirectCopy { var writerConn net.Conn - if inbound := session.InboundFromContext(ctx); inbound != nil && inbound.Conn != nil && ob != nil { + if inbound := session.InboundFromContext(ctx); inbound != nil && inbound.Conn != nil { writerConn = inbound.Conn if inbound.CanSpliceCopy == 2 { inbound.CanSpliceCopy = 1 } - if ob.CanSpliceCopy == 2 { // ob need to be passed in due to context can change + if ob != nil && ob.CanSpliceCopy == 2 { // ob need to be passed in due to context can change ob.CanSpliceCopy = 1 } } @@ -228,11 +228,11 @@ func XtlsWrite(reader buf.Reader, writer buf.Writer, timer signal.ActivityUpdate for { buffer, err := reader.ReadMultiBuffer() if trafficState.WriterSwitchToDirectCopy { - if inbound := session.InboundFromContext(ctx); inbound != nil && ob != nil { + if inbound := session.InboundFromContext(ctx); inbound != nil { if inbound.CanSpliceCopy == 2 { inbound.CanSpliceCopy = 1 } - if ob.CanSpliceCopy == 2 { + if ob != nil && ob.CanSpliceCopy == 2 { ob.CanSpliceCopy = 1 } } diff --git a/proxy/vless/inbound/inbound.go b/proxy/vless/inbound/inbound.go index 7d2dd507..d44b8c09 100644 --- a/proxy/vless/inbound/inbound.go +++ b/proxy/vless/inbound/inbound.go @@ -560,9 +560,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s var err error if requestAddons.Flow == vless.XRV { - outbounds := session.OutboundsFromContext(ctx) - ob := outbounds[len(outbounds) - 1] - err = encoding.XtlsWrite(serverReader, clientWriter, timer, connection, trafficState, ob, ctx) + err = encoding.XtlsWrite(serverReader, clientWriter, timer, connection, trafficState, nil, ctx) } else { // from serverReader.ReadMultiBuffer to clientWriter.WriteMultiBufer err = buf.Copy(serverReader, clientWriter, buf.UpdateActivity(timer))