Merge pull request #1945 from bas-vk/rpcparsing

Argument parsing can lead to panic in rpc channel
pull/1949/head
Jeffrey Wilcke 9 years ago
commit fd27f074fe
  1. 14
      rpc/api/eth_args.go
  2. 11
      rpc/comms/comms.go

@ -626,7 +626,12 @@ func (args *GetBlockByHashArgs) UnmarshalJSON(b []byte) (err error) {
args.IncludeTxs = obj[1].(bool)
return nil
if inclTx, ok := obj[1].(bool); ok {
args.IncludeTxs = inclTx
return nil
}
return shared.NewInvalidTypeError("includeTxs", "not a bool")
}
type GetBlockByNumberArgs struct {
@ -648,9 +653,12 @@ func (args *GetBlockByNumberArgs) UnmarshalJSON(b []byte) (err error) {
return err
}
args.IncludeTxs = obj[1].(bool)
if inclTx, ok := obj[1].(bool); ok {
args.IncludeTxs = inclTx
return nil
}
return nil
return shared.NewInvalidTypeError("includeTxs", "not a bool")
}
type BlockFilterArgs struct {

@ -62,13 +62,18 @@ type EthereumClient interface {
func handle(id int, conn net.Conn, api shared.EthereumApi, c codec.Codec) {
codec := c.New(conn)
defer func() {
if r := recover(); r != nil {
glog.Errorf("panic: %v\n", r)
}
codec.Close()
}()
for {
requests, isBatch, err := codec.ReadRequest()
if err == io.EOF {
codec.Close()
return
} else if err != nil {
codec.Close()
glog.V(logger.Debug).Infof("Closed IPC Conn %06d recv err - %v\n", id, err)
return
}
@ -87,7 +92,6 @@ func handle(id int, conn net.Conn, api shared.EthereumApi, c codec.Codec) {
err = codec.WriteResponse(responses[:responseCount])
if err != nil {
codec.Close()
glog.V(logger.Debug).Infof("Closed IPC Conn %06d send err - %v\n", id, err)
return
}
@ -98,7 +102,6 @@ func handle(id int, conn net.Conn, api shared.EthereumApi, c codec.Codec) {
rpcResponse = shared.NewRpcResponse(requests[0].Id, requests[0].Jsonrpc, res, err)
err = codec.WriteResponse(rpcResponse)
if err != nil {
codec.Close()
glog.V(logger.Debug).Infof("Closed IPC Conn %06d send err - %v\n", id, err)
return
}

Loading…
Cancel
Save