From 5719b9d22f522ad6581f85d091b105335d52decc Mon Sep 17 00:00:00 2001 From: Skyxim Date: Mon, 4 Apr 2022 22:28:47 +0800 Subject: [PATCH] fix: npe panic --- adapter/inbound/socket.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/adapter/inbound/socket.go b/adapter/inbound/socket.go index ebb2095e..f1d8c3da 100644 --- a/adapter/inbound/socket.go +++ b/adapter/inbound/socket.go @@ -13,9 +13,13 @@ func NewSocket(target socks5.Addr, conn net.Conn, source C.Type) *context.ConnCo metadata := parseSocksAddr(target) metadata.NetWork = C.TCP metadata.Type = source - if ip, port, err := parseAddr(conn.RemoteAddr().String()); err == nil { - metadata.SrcIP = ip - metadata.SrcPort = port + remoteAddr := conn.RemoteAddr() + // Filter when net.Addr interface is nil + if remoteAddr != nil { + if ip, port, err := parseAddr(remoteAddr.String()); err == nil { + metadata.SrcIP = ip + metadata.SrcPort = port + } } return context.NewConnContext(conn, metadata)