Permalink
Browse files

Fix malformed RPC params parsing

  • Loading branch information...
sammy007 committed Nov 10, 2017
1 parent 73e8c1a commit 39a30e7745652ae2bb92dbf73450fc02de95401f
Showing with 14 additions and 14 deletions.
  1. +7 −7 proxy/proto.go
  2. +3 −3 proxy/proxy.go
  3. +4 −4 proxy/stratum.go
View
@@ -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 {
View
@@ -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)
@@ -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)
}
View
@@ -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
@@ -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
@@ -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()

0 comments on commit 39a30e7

Please sign in to comment.