浏览代码

Max size JSON data. Closes #418

obscuren 10 年之前
父节点
当前提交
676a0de58d
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      rpc/http/server.go

+ 8 - 0
rpc/http/server.go

@@ -29,6 +29,8 @@ import (
 var rpchttplogger = logger.NewLogger("RPC-HTTP")
 var JSON rpc.JsonWrapper
 
+const maxSizeReqLength = 1024 * 1024 // 1MB
+
 func NewRpcHttpServer(pipe *xeth.XEth, address string, port int) (*RpcHttpServer, error) {
 	sport := fmt.Sprintf("%s:%d", address, port)
 	l, err := net.Listen("tcp", sport)
@@ -92,6 +94,12 @@ func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler {
 
 		rpchttplogger.DebugDetailln("Handling request")
 
+		if req.ContentLength > maxSizeReqLength {
+			jsonerr := &rpc.RpcErrorObject{-32700, "Error: Request too large"}
+			JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr})
+			return
+		}
+
 		reqParsed, reqerr := JSON.ParseRequestBody(req)
 		if reqerr != nil {
 			jsonerr := &rpc.RpcErrorObject{-32700, "Error: Could not parse request"}