From b004b9ec81c15ac4756b56e19c8268a8b46109d2 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Mon, 13 Mar 2023 13:24:42 +0800 Subject: [PATCH] Fix stack wireguard device returning non-nil interface containing nil pointer --- transport/wireguard/device_stack.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/transport/wireguard/device_stack.go b/transport/wireguard/device_stack.go index 3919a6b7..b2981e36 100644 --- a/transport/wireguard/device_stack.go +++ b/transport/wireguard/device_stack.go @@ -109,9 +109,17 @@ func (w *StackDevice) DialContext(ctx context.Context, network string, destinati } switch N.NetworkName(network) { case N.NetworkTCP: - return gonet.DialTCPWithBind(ctx, w.stack, bind, addr, networkProtocol) + tcpConn, err := gonet.DialTCPWithBind(ctx, w.stack, bind, addr, networkProtocol) + if err != nil { + return nil, err + } + return tcpConn, nil case N.NetworkUDP: - return gonet.DialUDP(w.stack, &bind, &addr, networkProtocol) + udpConn, err := gonet.DialUDP(w.stack, &bind, &addr, networkProtocol) + if err != nil { + return nil, err + } + return udpConn, nil default: return nil, E.Extend(N.ErrUnknownNetwork, network) } @@ -129,7 +137,11 @@ func (w *StackDevice) ListenPacket(ctx context.Context, destination M.Socksaddr) networkProtocol = header.IPv6ProtocolNumber bind.Addr = w.addr6 } - return gonet.DialUDP(w.stack, &bind, nil, networkProtocol) + udpConn, err := gonet.DialUDP(w.stack, &bind, nil, networkProtocol) + if err != nil { + return nil, err + } + return udpConn, nil } func (w *StackDevice) Start() error {