From ad85f0934aa018fc0280e8bcda5a6e0ba6e49ebb Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Mon, 2 Mar 2020 23:47:23 +0800 Subject: [PATCH] Fix: mutable SplitAddr cause panic --- adapters/outbound/shadowsocks.go | 7 ++++++- adapters/outbound/socks5.go | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/adapters/outbound/shadowsocks.go b/adapters/outbound/shadowsocks.go index 5e748f1c..5ad18df9 100644 --- a/adapters/outbound/shadowsocks.go +++ b/adapters/outbound/shadowsocks.go @@ -216,6 +216,11 @@ func (spc *ssPacketConn) ReadFrom(b []byte) (int, net.Addr, error) { return 0, nil, errors.New("parse addr error") } + udpAddr := addr.UDPAddr() + if udpAddr == nil { + return 0, nil, errors.New("parse addr error") + } + copy(b, b[len(addr):]) - return n - len(addr), addr.UDPAddr(), e + return n - len(addr), udpAddr, e } diff --git a/adapters/outbound/socks5.go b/adapters/outbound/socks5.go index ed976a6a..c8bd1bf5 100644 --- a/adapters/outbound/socks5.go +++ b/adapters/outbound/socks5.go @@ -3,6 +3,7 @@ package outbound import ( "context" "crypto/tls" + "errors" "fmt" "io" "io/ioutil" @@ -169,9 +170,15 @@ func (uc *socksPacketConn) ReadFrom(b []byte) (int, net.Addr, error) { if err != nil { return 0, nil, err } + + udpAddr := addr.UDPAddr() + if udpAddr == nil { + return 0, nil, errors.New("parse udp addr error") + } + // due to DecodeUDPPacket is mutable, record addr length copy(b, payload) - return n - len(addr) - 3, addr.UDPAddr(), nil + return n - len(addr) - 3, udpAddr, nil } func (uc *socksPacketConn) Close() error {