From a77a3d1334bf35163ff4ba703c3df4e20ad2709c Mon Sep 17 00:00:00 2001 From: spring23 <1628420979@qq.com> Date: Tue, 19 Sep 2023 16:03:46 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20nil=20pointer=20dereference=20caused?= =?UTF-8?q?=20by=20nil=20'cs'=20=E4=BF=AE=E5=A4=8D=E5=88=B7=E6=96=B0=20tok?= =?UTF-8?q?en=20=E6=97=B6=E8=8B=A5=E5=BD=93=E5=89=8D=E7=AD=BE=E5=90=8D?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E4=B8=8D=E5=8F=AF=E7=94=A8=E8=80=8C=E4=B8=BB?= =?UTF-8?q?=E7=AD=BE=E5=90=8D=E6=9C=8D=E5=8A=A1=E5=8F=AF=E7=94=A8=E4=BC=9A?= =?UTF-8?q?=E5=AF=BC=E8=87=B4panic=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82=20b?= =?UTF-8?q?tw,=20energy=20=E5=87=BA=E7=8E=B0decode=20error=E6=97=B6?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E5=87=BA=E5=AF=BC=E8=87=B4=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/gocq/qsign.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/gocq/qsign.go b/cmd/gocq/qsign.go index b6446fd75..5189144df 100644 --- a/cmd/gocq/qsign.go +++ b/cmd/gocq/qsign.go @@ -168,7 +168,7 @@ func energy(uin uint64, id string, _ string, salt []byte) ([]byte, error) { } data, err := hex.DecodeString(gjson.GetBytes(response, "data").String()) if err != nil { - log.Warnf("获取T544 sign时出现错误: %v", err) + log.Warnf("获取T544 sign时出现错误: %v (data: %v)", err, gjson.GetBytes(response, "data").String()) return nil, err } if len(data) == 0 { @@ -397,7 +397,7 @@ func signStartRefreshToken(interval int64) { cs, master := ss.get(), &base.SignServers[0] if (cs == nil || cs.URL != master.URL) && isServerAvaliable(master.URL) { ss.set(master) - log.Infof("主签名服务器可用,已切换至主签名服务器 %v", cs.URL) + log.Infof("主签名服务器可用,已切换至主签名服务器 %v", master.URL) } cs = ss.get() if cs == nil { From d4eff17fca0ccbea248e42c77eb913da8b6e9bd8 Mon Sep 17 00:00:00 2001 From: spring23 <1628420979@qq.com> Date: Tue, 19 Sep 2023 16:11:43 +0800 Subject: [PATCH 2/4] =?UTF-8?q?optimize:=20=E5=8F=AA=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=BA=86=E4=B8=80=E4=B8=AA=E7=AD=BE=E5=90=8D=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E6=97=B6=E4=B8=8D=E8=BF=9B=E8=A1=8C=E6=A3=80=E6=9F=A5=E5=92=8C?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/gocq/qsign.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/gocq/qsign.go b/cmd/gocq/qsign.go index 5189144df..0a788ed76 100644 --- a/cmd/gocq/qsign.go +++ b/cmd/gocq/qsign.go @@ -59,6 +59,9 @@ func getAvaliableSignServer() (*config.SignServer, error) { if len(base.SignServers) == 0 { return nil, errors.New("no sign server configured") } + if len(base.SignServers) == 1 { // 只配置了一个签名服务时不检查以及切换 + return &base.SignServers[0], nil + } maxCount := base.Account.MaxCheckCount if maxCount == 0 { if errn.hasOver(3) { From 130efa401b1983abb609551ac978957a5160d6ec Mon Sep 17 00:00:00 2001 From: spring23 <1628420979@qq.com> Date: Wed, 20 Sep 2023 09:57:23 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix(qsign):=20=E5=88=B7=E6=96=B0token?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E6=9C=AA=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复在qsign崩溃重启前请求了签名服务器导致当前签名服务器被标记为不可用(`ss.set(nil)`), 从而不会再执行sign请求(除非有其他请求签名服务器的操作) 这可能导致下一次刷新token提示uin is not registered或者提示未初始化 --- cmd/gocq/qsign.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cmd/gocq/qsign.go b/cmd/gocq/qsign.go index 0a788ed76..e16f1e059 100644 --- a/cmd/gocq/qsign.go +++ b/cmd/gocq/qsign.go @@ -27,6 +27,10 @@ import ( type currentSignServer atomic.Pointer[config.SignServer] func (c *currentSignServer) get() *config.SignServer { + if len(base.SignServers) == 1 { + // 只配置了一个签名服务时不检查以及切换, 在get阶段返回,防止返回nil导致其他bug(可能) + return &base.SignServers[0] + } return (*atomic.Pointer[config.SignServer])(c).Load() } @@ -59,9 +63,6 @@ func getAvaliableSignServer() (*config.SignServer, error) { if len(base.SignServers) == 0 { return nil, errors.New("no sign server configured") } - if len(base.SignServers) == 1 { // 只配置了一个签名服务时不检查以及切换 - return &base.SignServers[0], nil - } maxCount := base.Account.MaxCheckCount if maxCount == 0 { if errn.hasOver(3) { @@ -213,7 +214,7 @@ func signCallback(uin string, results []gjson.Result, t string) { body, _ := hex.DecodeString(result.Get("body").String()) ret, err := cli.SendSsoPacket(cmd, body) if err != nil || len(ret) == 0 { - log.Warnf("Callback error: %v, Or response data is empty", err) + log.Warnf("Callback error: %v, or response data is empty", err) continue // 发送 SsoPacket 出错或返回数据为空时跳过 } signSubmit(uin, cmd, callbackID, ret, t) @@ -292,11 +293,14 @@ func sign(seq uint64, uin string, cmd string, qua string, buff []byte) (sign []b i := 0 for { cs := ss.get() + sign, extra, token, err = signRequset(seq, uin, cmd, qua, buff) if cs == nil { + // 最好在请求后判断,否则若被设置为nil后不会再请求签名, + // 导致在下一次有请求签名服务操作之前,ss无法更新 err = errors.New("nil signserver") + log.Warn("nil sign-server") // 返回的err并不会log出来,加条日志 return } - sign, extra, token, err = signRequset(seq, uin, cmd, qua, buff) if err != nil { log.Warnf("获取sso sign时出现错误: %v. server: %v", err, cs.URL) } From 3dbd3e0b52ac40b55b0d2246b11f48cffca7cef4 Mon Sep 17 00:00:00 2001 From: spring23 <1628420979@qq.com> Date: Wed, 20 Sep 2023 15:01:31 +0800 Subject: [PATCH 4/4] update qsign.go --- cmd/gocq/qsign.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/gocq/qsign.go b/cmd/gocq/qsign.go index e16f1e059..b51c398b8 100644 --- a/cmd/gocq/qsign.go +++ b/cmd/gocq/qsign.go @@ -292,8 +292,9 @@ var lastToken = "" func sign(seq uint64, uin string, cmd string, qua string, buff []byte) (sign []byte, extra []byte, token []byte, err error) { i := 0 for { - cs := ss.get() + sign, extra, token, err = signRequset(seq, uin, cmd, qua, buff) + cs := ss.get() if cs == nil { // 最好在请求后判断,否则若被设置为nil后不会再请求签名, // 导致在下一次有请求签名服务操作之前,ss无法更新