From 6d375ac37ea76429d04ba71434eaa5860e9ffede Mon Sep 17 00:00:00 2001 From: Dreamacro <305009791@qq.com> Date: Mon, 28 Oct 2019 12:58:39 +0800 Subject: [PATCH] Fix: new tracker crash when rule is nil --- tunnel/tracker.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tunnel/tracker.go b/tunnel/tracker.go index 77e442b8..e96c2835 100644 --- a/tunnel/tracker.go +++ b/tunnel/tracker.go @@ -56,6 +56,11 @@ func (tt *tcpTracker) Close() error { func newTCPTracker(conn C.Conn, manager *Manager, metadata *C.Metadata, rule C.Rule) *tcpTracker { uuid, _ := uuid.NewV4() + ruleType := "" + if rule != nil { + ruleType = rule.RuleType().String() + } + t := &tcpTracker{ Conn: conn, manager: manager, @@ -64,7 +69,7 @@ func newTCPTracker(conn C.Conn, manager *Manager, metadata *C.Metadata, rule C.R Start: time.Now(), Metadata: metadata, Chain: conn.Chains(), - Rule: rule.RuleType().String(), + Rule: ruleType, }, } @@ -105,6 +110,11 @@ func (ut *udpTracker) Close() error { func newUDPTracker(conn C.PacketConn, manager *Manager, metadata *C.Metadata, rule C.Rule) *udpTracker { uuid, _ := uuid.NewV4() + ruleType := "" + if rule != nil { + ruleType = rule.RuleType().String() + } + ut := &udpTracker{ PacketConn: conn, manager: manager, @@ -113,7 +123,7 @@ func newUDPTracker(conn C.PacketConn, manager *Manager, metadata *C.Metadata, ru Start: time.Now(), Metadata: metadata, Chain: conn.Chains(), - Rule: rule.RuleType().String(), + Rule: ruleType, }, }