Skip to content

Commit

Permalink
Fix malformed RPC params parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
sammy007 committed Nov 10, 2017
1 parent 73e8c1a commit 39a30e7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions proxy/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &params)
err := json.Unmarshal(req.Params, &params)
if err != nil {
log.Printf("Unable to parse params from %v", cs.ip)
s.policy.ApplyMalformedPolicy(cs.ip)
Expand Down Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions proxy/stratum.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &params)
err := json.Unmarshal(req.Params, &params)
if err != nil {
log.Println("Malformed stratum request params from", cs.ip)
return err
Expand All @@ -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, &params)
err := json.Unmarshal(req.Params, &params)
if err != nil {
log.Println("Malformed stratum request params from", cs.ip)
return err
Expand All @@ -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()

Expand All @@ -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()

Expand Down

0 comments on commit 39a30e7

Please sign in to comment.