From 14c9cf1b977612afe2e5ebd2a338e8c36174b234 Mon Sep 17 00:00:00 2001 From: Kr328 Date: Wed, 24 Jun 2020 19:46:37 +0800 Subject: [PATCH] Fix: domain trie crash if not match in #758 (#762) --- component/trie/domain.go | 2 +- component/trie/domain_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/component/trie/domain.go b/component/trie/domain.go index 8df22792..909cccf0 100644 --- a/component/trie/domain.go +++ b/component/trie/domain.go @@ -98,7 +98,7 @@ func (t *DomainTrie) Search(domain string) *Node { n := t.search(t.root, parts) - if n.Data == nil { + if n == nil || n.Data == nil { return nil } diff --git a/component/trie/domain_test.go b/component/trie/domain_test.go index 3e150717..61340cde 100644 --- a/component/trie/domain_test.go +++ b/component/trie/domain_test.go @@ -27,6 +27,7 @@ func TestTrie_Basic(t *testing.T) { assert.NotNil(t, tree.Insert("", localIP)) assert.Nil(t, tree.Search("")) assert.NotNil(t, tree.Search("localhost")) + assert.Nil(t, tree.Search("www.google.com")) } func TestTrie_Wildcard(t *testing.T) {