rpc: fix issue with null JSON-RPC messages (#21497)
This commit is contained in:
13
rpc/json.go
13
rpc/json.go
@ -202,15 +202,22 @@ func (c *jsonCodec) remoteAddr() string {
|
||||
return c.remote
|
||||
}
|
||||
|
||||
func (c *jsonCodec) readBatch() (msg []*jsonrpcMessage, batch bool, err error) {
|
||||
func (c *jsonCodec) readBatch() (messages []*jsonrpcMessage, batch bool, err error) {
|
||||
// Decode the next JSON object in the input stream.
|
||||
// This verifies basic syntax, etc.
|
||||
var rawmsg json.RawMessage
|
||||
if err := c.decode(&rawmsg); err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
msg, batch = parseMessage(rawmsg)
|
||||
return msg, batch, nil
|
||||
messages, batch = parseMessage(rawmsg)
|
||||
for i, msg := range messages {
|
||||
if msg == nil {
|
||||
// Message is JSON 'null'. Replace with zero value so it
|
||||
// will be treated like any other invalid message.
|
||||
messages[i] = new(jsonrpcMessage)
|
||||
}
|
||||
}
|
||||
return messages, batch, nil
|
||||
}
|
||||
|
||||
func (c *jsonCodec) writeJSON(ctx context.Context, v interface{}) error {
|
||||
|
Reference in New Issue
Block a user