From 1c221cdf6d6d36d80a69f975593fe50563c8f647 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sun, 26 Mar 2017 22:03:06 -0700 Subject: [PATCH] tun2: avoid intN panic --- lib/tun2/server.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/tun2/server.go b/lib/tun2/server.go index 0ebfdc4..f9e4c64 100644 --- a/lib/tun2/server.go +++ b/lib/tun2/server.go @@ -365,7 +365,7 @@ func (s *Server) RoundTrip(req *http.Request) (*http.Response, error) { val, ok := s.domains.Get(req.Host) if ok { conns, ok = val.([]*Connection) - if !ok || len(conns) == 0 { + if !ok { ln.Error(errors.New("no backend connected"), ln.F{ "action": "no_backend_connected", "remote": req.RemoteAddr, @@ -385,6 +385,10 @@ func (s *Server) RoundTrip(req *http.Request) (*http.Response, error) { } } + if len(conns) == 0 { + return nil, errors.New("no backend connected") + } + c := conns[rand.Intn(len(conns))] stream, err := c.session.OpenStream()