From 51ce6720763eebdf21fca73b27d13a975a61e5f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 28 Nov 2022 11:45:33 +0800 Subject: [PATCH] Fix crash when input bad method in shadowsocks multi-user inbound --- inbound/shadowsocks.go | 2 +- inbound/shadowsocks_multi.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/inbound/shadowsocks.go b/inbound/shadowsocks.go index e1d60950..2bbb304b 100644 --- a/inbound/shadowsocks.go +++ b/inbound/shadowsocks.go @@ -70,7 +70,7 @@ func newShadowsocks(ctx context.Context, router adapter.Router, logger log.Conte case common.Contains(shadowaead_2022.List, options.Method): inbound.service, err = shadowaead_2022.NewServiceWithPassword(options.Method, options.Password, udpTimeout, inbound.upstreamContextHandler()) default: - err = E.New("shadowsocks: unsupported method: ", options.Method) + err = E.New("unsupported method: ", options.Method) } inbound.packetUpstream = inbound.service return inbound, err diff --git a/inbound/shadowsocks_multi.go b/inbound/shadowsocks_multi.go index 4a001be7..fc9debd5 100644 --- a/inbound/shadowsocks_multi.go +++ b/inbound/shadowsocks_multi.go @@ -13,6 +13,7 @@ import ( "github.com/sagernet/sing/common" "github.com/sagernet/sing/common/auth" "github.com/sagernet/sing/common/buf" + E "github.com/sagernet/sing/common/exceptions" F "github.com/sagernet/sing/common/format" N "github.com/sagernet/sing/common/network" ) @@ -48,6 +49,9 @@ func newShadowsocksMulti(ctx context.Context, router adapter.Router, logger log. } else { udpTimeout = int64(C.UDPTimeout.Seconds()) } + if !common.Contains(shadowaead_2022.List, options.Method) { + return nil, E.New("unsupported method: " + options.Method) + } service, err := shadowaead_2022.NewMultiServiceWithPassword[int]( options.Method, options.Password,