diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-10-29 23:55:51 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-10-29 23:55:51 +0800 |
commit | fd27f074feecec2f1e4c8041ff04ddac8d0ab6a3 (patch) | |
tree | b8e134548c06002421c776adf35a69758340a665 | |
parent | 8202bae070ae80db572dc37895e52f3e4e75585b (diff) | |
parent | c3c5f8b654f9ddaeedeb2d3d5d1caf000e08320e (diff) | |
download | go-tangerine-fd27f074feecec2f1e4c8041ff04ddac8d0ab6a3.tar go-tangerine-fd27f074feecec2f1e4c8041ff04ddac8d0ab6a3.tar.gz go-tangerine-fd27f074feecec2f1e4c8041ff04ddac8d0ab6a3.tar.bz2 go-tangerine-fd27f074feecec2f1e4c8041ff04ddac8d0ab6a3.tar.lz go-tangerine-fd27f074feecec2f1e4c8041ff04ddac8d0ab6a3.tar.xz go-tangerine-fd27f074feecec2f1e4c8041ff04ddac8d0ab6a3.tar.zst go-tangerine-fd27f074feecec2f1e4c8041ff04ddac8d0ab6a3.zip |
Merge pull request #1945 from bas-vk/rpcparsing
Argument parsing can lead to panic in rpc channel
-rw-r--r-- | rpc/api/eth_args.go | 14 | ||||
-rw-r--r-- | rpc/comms/comms.go | 11 |
2 files changed, 18 insertions, 7 deletions
diff --git a/rpc/api/eth_args.go b/rpc/api/eth_args.go index 6aca6a663..457350d74 100644 --- a/rpc/api/eth_args.go +++ b/rpc/api/eth_args.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 { diff --git a/rpc/comms/comms.go b/rpc/comms/comms.go index 731b2f62e..61fba5722 100644 --- a/rpc/comms/comms.go +++ b/rpc/comms/comms.go @@ -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 } |