mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-05 14:38:42 +00:00
rpc: fix method-name matched before maxMethodNameLength (#35038)
Co-authored-by: MariusVanDerWijden <m.vanderwijden@live.de>
This commit is contained in:
parent
9d21f6ebd5
commit
f4a90d178a
2 changed files with 6 additions and 7 deletions
|
|
@ -502,6 +502,10 @@ func (h *handler) handleCallMsg(ctx *callProc, msg *jsonrpcMessage) *jsonrpcMess
|
||||||
|
|
||||||
// handleCall processes method calls.
|
// handleCall processes method calls.
|
||||||
func (h *handler) handleCall(cp *callProc, msg *jsonrpcMessage) *jsonrpcMessage {
|
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() {
|
if msg.isSubscribe() {
|
||||||
return h.handleSubscribe(cp, msg)
|
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)
|
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)
|
callb, service, method := h.reg.callback(msg.Method)
|
||||||
|
|
||||||
// If the method is not found, return an error.
|
// If the method is not found, return an error.
|
||||||
|
|
|
||||||
|
|
@ -432,10 +432,10 @@ func TestWebsocketMethodNameLengthLimit(t *testing.T) {
|
||||||
isSubscription: true,
|
isSubscription: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "subscription name too long",
|
name: "method name too long subscribe",
|
||||||
method: string(make([]byte, maxMethodNameLength+1)) + "_subscribe",
|
method: string(make([]byte, maxMethodNameLength+1)) + "_subscribe",
|
||||||
params: []interface{}{"newHeads"},
|
params: []interface{}{"newHeads"},
|
||||||
expectedError: "subscription name too long",
|
expectedError: "method name too long",
|
||||||
isSubscription: true,
|
isSubscription: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue