From 2897ce916a89ae676588d77cb636cf570d31316a Mon Sep 17 00:00:00 2001 From: Dreamacro <305009791@qq.com> Date: Fri, 15 Jun 2018 00:44:31 +0800 Subject: [PATCH] Fixed: crash when net.ResolveIPAddr error --- proxy/http/server.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/proxy/http/server.go b/proxy/http/server.go index c06a8f31..9dcefd06 100644 --- a/proxy/http/server.go +++ b/proxy/http/server.go @@ -59,7 +59,12 @@ func handleTunneling(w http.ResponseWriter, r *http.Request) { func parseHttpAddr(target string) *C.Addr { host, port, _ := net.SplitHostPort(target) - ipAddr, _ := net.ResolveIPAddr("ip", host) + ipAddr, err := net.ResolveIPAddr("ip", host) + var resolveIP *net.IP + if err == nil { + resolveIP = &ipAddr.IP + } + var addType int ip := net.ParseIP(host) switch { @@ -75,7 +80,7 @@ func parseHttpAddr(target string) *C.Addr { NetWork: C.TCP, AddrType: addType, Host: host, - IP: &ipAddr.IP, + IP: resolveIP, Port: port, } }