Closed
Description
In internal/protocol/protocol.go line 187, the protocol object passes a NilPointer as the first parameter to method handleResponse
, but the handleResponse
method gets the field from the first parameter without any NilPointer checking.
func (p *Protocol) Connect(tr transport.Transport) error {
p.transport = tr
tr.SetCloseHandler(func() {
p.handleClose()
})
tr.SetErrorHandler(func(err error) {
p.handleError(err)
})
tr.SetMessageHandler(func(ctx context.Context, message *transport.BaseJsonRpcMessage) {
switch m := message.Type; {
case m == transport.BaseMessageTypeJSONRPCRequestType:
p.handleRequest(ctx, message.JsonRpcRequest)
case m == transport.BaseMessageTypeJSONRPCNotificationType:
p.handleNotification(message.JsonRpcNotification)
case m == transport.BaseMessageTypeJSONRPCResponseType:
p.handleResponse(message.JsonRpcResponse, nil)
case m == transport.BaseMessageTypeJSONRPCErrorType:
// pass a nil pointer to the method
p.handleResponse(nil, message.JsonRpcError)
}
})
return tr.Start(context.Background())
}
func (p *Protocol) handleResponse(response *transport.BaseJSONRPCResponse, errResp *transport.BaseJSONRPCError) {
// get response.Id directly without any checking
var id = response.Id
var result interface{}
var err error
if errResp != nil {
id = errResp.Id
err = fmt.Errorf("RPC error %d: %s", errResp.Error.Code, errResp.Error.Message)
} else {
// Parse the response
result = response.Result
}
p.mu.RLock()
ch := p.responseHandlers[id]
p.mu.RUnlock()
if ch != nil {
ch <- &responseEnvelope{
response: result,
err: err,
}
}
}
Metadata
Metadata
Assignees
Labels
No labels