From 057e6284b287d9ae6042633e4d8f21eb71641ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E6=89=87=E6=BB=91=E7=BF=94=E7=BF=BC?= Date: Mon, 4 Nov 2024 23:39:04 +0800 Subject: [PATCH] UDS: prevent crash when proxy udp (#3967) * net: Prevent nil pointer err in NetAddr() * Fix dsworker saddr problem --- app/proxyman/inbound/worker.go | 3 ++- common/net/destination.go | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/proxyman/inbound/worker.go b/app/proxyman/inbound/worker.go index a14a338f..14df725d 100644 --- a/app/proxyman/inbound/worker.go +++ b/app/proxyman/inbound/worker.go @@ -464,7 +464,8 @@ func (w *dsWorker) callback(conn stat.Connection) { } } ctx = session.ContextWithInbound(ctx, &session.Inbound{ - Source: net.DestinationFromAddr(conn.RemoteAddr()), + // Unix have no source addr, so we use gateway as source for log. + Source: net.UnixDestination(w.address), Gateway: net.UnixDestination(w.address), Tag: w.tag, Conn: conn, diff --git a/common/net/destination.go b/common/net/destination.go index 90f8298b..952dcc6b 100644 --- a/common/net/destination.go +++ b/common/net/destination.go @@ -89,10 +89,12 @@ func UnixDestination(address Address) Destination { // NetAddr returns the network address in this Destination in string form. func (d Destination) NetAddr() string { addr := "" - if d.Network == Network_TCP || d.Network == Network_UDP { - addr = d.Address.String() + ":" + d.Port.String() - } else if d.Network == Network_UNIX { - addr = d.Address.String() + if d.Address != nil { + if d.Network == Network_TCP || d.Network == Network_UDP { + addr = d.Address.String() + ":" + d.Port.String() + } else if d.Network == Network_UNIX { + addr = d.Address.String() + } } return addr }