From 39a30e7745652ae2bb92dbf73450fc02de95401f Mon Sep 17 00:00:00 2001 From: Sammy Libre Date: Fri, 10 Nov 2017 09:16:49 +0500 Subject: [PATCH] Fix malformed RPC params parsing --- proxy/proto.go | 14 +++++++------- proxy/proxy.go | 6 +++--- proxy/stratum.go | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/proxy/proto.go b/proxy/proto.go index 5cd927c48..16de94340 100644 --- a/proxy/proto.go +++ b/proxy/proto.go @@ -3,9 +3,9 @@ package proxy import "encoding/json" type JSONRpcReq struct { - Id *json.RawMessage `json:"id"` - Method string `json:"method"` - Params *json.RawMessage `json:"params"` + Id json.RawMessage `json:"id"` + Method string `json:"method"` + Params json.RawMessage `json:"params"` } type StratumReq struct { @@ -22,10 +22,10 @@ type JSONPushMessage struct { } type JSONRpcResp struct { - Id *json.RawMessage `json:"id"` - Version string `json:"jsonrpc"` - Result interface{} `json:"result"` - Error interface{} `json:"error,omitempty"` + Id json.RawMessage `json:"id"` + Version string `json:"jsonrpc"` + Result interface{} `json:"result"` + Error interface{} `json:"error,omitempty"` } type SubmitReply struct { diff --git a/proxy/proxy.go b/proxy/proxy.go index 100338099..1ace5502a 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -241,7 +241,7 @@ func (cs *Session) handleMessage(s *ProxyServer, r *http.Request, req *JSONRpcRe case "eth_submitWork": if req.Params != nil { var params []string - err := json.Unmarshal(*req.Params, ¶ms) + err := json.Unmarshal(req.Params, ¶ms) if err != nil { log.Printf("Unable to parse params from %v", cs.ip) s.policy.ApplyMalformedPolicy(cs.ip) @@ -269,12 +269,12 @@ func (cs *Session) handleMessage(s *ProxyServer, r *http.Request, req *JSONRpcRe } } -func (cs *Session) sendResult(id *json.RawMessage, result interface{}) error { +func (cs *Session) sendResult(id json.RawMessage, result interface{}) error { message := JSONRpcResp{Id: id, Version: "2.0", Error: nil, Result: result} return cs.enc.Encode(&message) } -func (cs *Session) sendError(id *json.RawMessage, reply *ErrorReply) error { +func (cs *Session) sendError(id json.RawMessage, reply *ErrorReply) error { message := JSONRpcResp{Id: id, Version: "2.0", Error: reply} return cs.enc.Encode(&message) } diff --git a/proxy/stratum.go b/proxy/stratum.go index dfc84d2d8..ff3b61ac7 100644 --- a/proxy/stratum.go +++ b/proxy/stratum.go @@ -105,7 +105,7 @@ func (cs *Session) handleTCPMessage(s *ProxyServer, req *StratumReq) error { switch req.Method { case "eth_submitLogin": var params []string - err := json.Unmarshal(*req.Params, ¶ms) + err := json.Unmarshal(req.Params, ¶ms) if err != nil { log.Println("Malformed stratum request params from", cs.ip) return err @@ -123,7 +123,7 @@ func (cs *Session) handleTCPMessage(s *ProxyServer, req *StratumReq) error { return cs.sendTCPResult(req.Id, &reply) case "eth_submitWork": var params []string - err := json.Unmarshal(*req.Params, ¶ms) + err := json.Unmarshal(req.Params, ¶ms) if err != nil { log.Println("Malformed stratum request params from", cs.ip) return err @@ -141,7 +141,7 @@ func (cs *Session) handleTCPMessage(s *ProxyServer, req *StratumReq) error { } } -func (cs *Session) sendTCPResult(id *json.RawMessage, result interface{}) error { +func (cs *Session) sendTCPResult(id json.RawMessage, result interface{}) error { cs.Lock() defer cs.Unlock() @@ -157,7 +157,7 @@ func (cs *Session) pushNewJob(result interface{}) error { return cs.enc.Encode(&message) } -func (cs *Session) sendTCPError(id *json.RawMessage, reply *ErrorReply) error { +func (cs *Session) sendTCPError(id json.RawMessage, reply *ErrorReply) error { cs.Lock() defer cs.Unlock()