Skip to content

Commit

Permalink
Add more fuzz rules support @Release
Browse files Browse the repository at this point in the history
  • Loading branch information
wweir committed Jan 28, 2019
1 parent c209031 commit 8194083
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
5 changes: 5 additions & 0 deletions conf/sower.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ blocklist=[
"*.blogspot.com", # blogspot
"*.wikipedia.org", # wikipeida
]
whitelist=[
"iamp.*.*.*",
"iamp.*.*",
"imap-mail.*.*",
]
verbose=0
2 changes: 1 addition & 1 deletion dns/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func init() {

//first init
blockList = loadRules("block", conf.Conf.BlockList)
suggestList = loadRules("suggest", conf.Conf.BlockList)
suggestList = loadRules("suggest", conf.Conf.Suggestions)
whiteList = loadRules("white", conf.Conf.WhiteList)
whiteList.Add(host)

Expand Down
18 changes: 11 additions & 7 deletions util/suffix_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,27 @@ func (n *node) add(secs []string) {
}

func (n *Node) Match(item string) bool {
return n.matchSecs(strings.Split(n.trim(item), n.sep))
return n.matchSecs(strings.Split(n.trim(item), n.sep), false)
}

func (n *node) matchSecs(secs []string) bool {
func (n *node) matchSecs(secs []string, fuzzNode bool) bool {
length := len(secs)
if length == 0 {
if _, ok := n.node[""]; ok {
return true
}
_, ok := n.node["*"]
return ok
if _, ok := n.node["*"]; ok {
return !fuzzNode
}
return false
}

if n, ok := n.node[secs[length-1]]; ok {
return n.matchSecs(secs[:length-1])
return n.matchSecs(secs[:length-1], false)
}
if n, ok := n.node["*"]; ok {
return n.matchSecs(secs[:length-1], true)
}

_, ok := n.node["*"]
return ok
return false
}
17 changes: 17 additions & 0 deletions util/suffix_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ func TestNode_Match(t *testing.T) {
{"a.wweir.cc", true},
{"b.wweir.cc", true},
},
}, {
"fuzz3",
NewNodeFromRules(".", "a.*.cc"),
[]test{
{"wweir.cc", false},
{"a.wweir.cc", true},
{"b.wweir.cc", false},
},
}, {
"fuzz4",
NewNodeFromRules(".", "*.*.cc", "iamp.*.*"),
[]test{
{"wweir.cc", false},
{"a.wweir.cc", true},
{"b.wweir.cc", true},
{"iamp.wweir.cc", true},
},
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 8194083

Please sign in to comment.