From b38effb7b06da4c7164d27041dd2a5f3200f041f Mon Sep 17 00:00:00 2001 From: Weixie Cui Date: Sat, 23 May 2026 23:46:56 +0800 Subject: [PATCH] rpc: fix method-name matched before maxMethodNameLength --- rpc/handler.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/rpc/handler.go b/rpc/handler.go index 89fc78236c..a9ffdc7071 100644 --- a/rpc/handler.go +++ b/rpc/handler.go @@ -502,6 +502,10 @@ func (h *handler) handleCallMsg(ctx *callProc, msg *jsonrpcMessage) *jsonrpcMess // handleCall processes method calls. func (h *handler) handleCall(cp *callProc, msg *jsonrpcMessage) *jsonrpcMessage { + // Check method name length + if len(msg.Method) > maxMethodNameLength { + return msg.errorResponse(&invalidRequestError{fmt.Sprintf("method name too long: %d > %d", len(msg.Method), maxMethodNameLength)}) + } if msg.isSubscribe() { return h.handleSubscribe(cp, msg) } @@ -512,11 +516,6 @@ func (h *handler) handleCall(cp *callProc, msg *jsonrpcMessage) *jsonrpcMessage } return h.runMethod(cp.ctx, msg, h.unsubscribeCb, args) } - - // Check method name length - if len(msg.Method) > maxMethodNameLength { - return msg.errorResponse(&invalidRequestError{fmt.Sprintf("method name too long: %d > %d", len(msg.Method), maxMethodNameLength)}) - } callb, service, method := h.reg.callback(msg.Method) // If the method is not found, return an error.