From 52fe72120220a6613f9fdb44c66ea4f130b8f3da Mon Sep 17 00:00:00 2001 From: fatedier Date: Tue, 20 Dec 2016 01:30:10 +0800 Subject: [PATCH] frps: fix a panic bug caused by reading map --- src/cmd/frps/control.go | 4 ++-- src/models/server/config.go | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cmd/frps/control.go b/src/cmd/frps/control.go index d0da95c..385642b 100644 --- a/src/cmd/frps/control.go +++ b/src/cmd/frps/control.go @@ -94,7 +94,7 @@ func controlWorker(c *conn.Conn) { return } - s, ok := server.ProxyServers[cliReq.ProxyName] + s, ok := server.GetProxyServer(cliReq.ProxyName) if !ok { log.Warn("ProxyName [%s] does not exist now", cliReq.ProxyName) return @@ -212,7 +212,7 @@ func doLogin(req *msg.ControlReq, c *conn.Conn) (ret int64, info string) { s *server.ProxyServer ok bool ) - s, ok = server.ProxyServers[req.ProxyName] + s, ok = server.GetProxyServer(req.ProxyName) if req.PrivilegeMode && req.Type == consts.NewCtlConn { log.Debug("ProxyName [%s], doLogin and privilege mode is enabled", req.ProxyName) } else { diff --git a/src/models/server/config.go b/src/models/server/config.go index 08a5cb8..5d92c74 100644 --- a/src/models/server/config.go +++ b/src/models/server/config.go @@ -392,3 +392,10 @@ func DeleteProxy(proxyName string) { defer ProxyServersMutex.Unlock() delete(ProxyServers, proxyName) } + +func GetProxyServer(proxyName string) (p *ProxyServer, ok bool) { + ProxyServersMutex.RLock() + defer ProxyServersMutex.RUnlock() + p, ok = ProxyServers[proxyName] + return +}