From b9b8632362c3b460694513c81b61e8c21f521f9e Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Wed, 24 Apr 2019 10:29:29 +0800 Subject: [PATCH] Fix: add missing error check --- adapters/outbound/direct.go | 5 ++++- adapters/outbound/shadowsocks.go | 11 +++++++++-- tunnel/tunnel.go | 7 ++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/adapters/outbound/direct.go b/adapters/outbound/direct.go index 1bd0a6f6..6cf18c09 100644 --- a/adapters/outbound/direct.go +++ b/adapters/outbound/direct.go @@ -30,7 +30,10 @@ func (d *Direct) DialUDP(metadata *C.Metadata) (net.PacketConn, net.Addr, error) return nil, nil, err } - addr, _ := net.ResolveUDPAddr("udp", net.JoinHostPort(metadata.String(), metadata.Port)) + addr, err := net.ResolveUDPAddr("udp", net.JoinHostPort(metadata.String(), metadata.Port)) + if err != nil { + return nil, nil, err + } return pc, addr, nil } diff --git a/adapters/outbound/shadowsocks.go b/adapters/outbound/shadowsocks.go index f477d9d3..b51f2354 100644 --- a/adapters/outbound/shadowsocks.go +++ b/adapters/outbound/shadowsocks.go @@ -88,8 +88,15 @@ func (ss *ShadowSocks) DialUDP(metadata *C.Metadata) (net.PacketConn, net.Addr, return nil, nil, err } - addr, _ := net.ResolveUDPAddr("udp", ss.server) - remoteAddr, _ := net.ResolveUDPAddr("udp", net.JoinHostPort(metadata.String(), metadata.Port)) + addr, err := net.ResolveUDPAddr("udp", ss.server) + if err != nil { + return nil, nil, err + } + + remoteAddr, err := net.ResolveUDPAddr("udp", net.JoinHostPort(metadata.String(), metadata.Port)) + if err != nil { + return nil, nil, err + } pc = ss.cipher.PacketConn(pc) return &ssUDPConn{PacketConn: pc, rAddr: remoteAddr}, addr, nil diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index 775f2f1c..7af3daf3 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -144,7 +144,12 @@ func (t *Tunnel) handleConn(localConn C.ServerAdapter) { } if metadata.NetWork == C.UDP { - pc, addr, _ := proxy.DialUDP(metadata) + pc, addr, err := proxy.DialUDP(metadata) + defer pc.Close() + if err != nil { + log.Warnln("Proxy[%s] connect [%s --> %s] error: %s", proxy.Name(), metadata.SourceIP.String(), metadata.String(), err.Error()) + } + t.handleUDPOverTCP(localConn, pc, addr) return }