From 254d2655f8d19054d150e1e6c58f0e47906643ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 31 Jul 2018 12:14:05 +0300 Subject: [PATCH] rpc: sanitize timeout values for library use --- rpc/http.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/rpc/http.go b/rpc/http.go index 16fb61b0fe..f3bd1f29c5 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -31,6 +31,7 @@ import ( "sync" "time" + "github.com/ethereum/go-ethereum/log" "github.com/rs/cors" ) @@ -198,6 +199,20 @@ func NewHTTPServer(cors []string, vhosts []string, timeouts HTTPTimeouts, srv *S handler := newCorsHandler(srv, cors) handler = newVHostHandler(vhosts, handler) + // Make sure timeout values are meaningful + if timeouts.ReadTimeout < time.Second { + log.Warn("Sanitizing invalid HTTP read timeout", "provided", timeouts.ReadTimeout, "updated", DefaultHTTPTimeouts.ReadTimeout) + timeouts.ReadTimeout = DefaultHTTPTimeouts.ReadTimeout + } + if timeouts.WriteTimeout < time.Second { + log.Warn("Sanitizing invalid HTTP write timeout", "provided", timeouts.WriteTimeout, "updated", DefaultHTTPTimeouts.WriteTimeout) + timeouts.WriteTimeout = DefaultHTTPTimeouts.WriteTimeout + } + if timeouts.IdleTimeout < time.Second { + log.Warn("Sanitizing invalid HTTP idle timeout", "provided", timeouts.IdleTimeout, "updated", DefaultHTTPTimeouts.IdleTimeout) + timeouts.IdleTimeout = DefaultHTTPTimeouts.IdleTimeout + } + // Bundle and start the HTTP server return &http.Server{ Handler: handler, ReadTimeout: timeouts.ReadTimeout,