mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-24 01:21:29 +00:00
fix(common): strmatcher match domain safety
This commit is contained in:
parent
cd1d000860
commit
fce86aad33
|
@ -225,7 +225,11 @@ func (ac *ACAutomaton) Match(s string) bool {
|
||||||
// 2. the match string is through a fail edge. NOT FULL MATCH
|
// 2. the match string is through a fail edge. NOT FULL MATCH
|
||||||
// 2.1 Through a fail edge, but there exists a valid node. SUBSTR
|
// 2.1 Through a fail edge, but there exists a valid node. SUBSTR
|
||||||
for i := len(s) - 1; i >= 0; i-- {
|
for i := len(s) - 1; i >= 0; i-- {
|
||||||
idx := char2Index[s[i]]
|
chr := int(s[i])
|
||||||
|
if chr >= len(char2Index) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
idx := char2Index[chr]
|
||||||
fullMatch = fullMatch && ac.trie[node][idx].edgeType
|
fullMatch = fullMatch && ac.trie[node][idx].edgeType
|
||||||
node = ac.trie[node][idx].nextNode
|
node = ac.trie[node][idx].nextNode
|
||||||
switch ac.exists[node].matchType {
|
switch ac.exists[node].matchType {
|
||||||
|
|
|
@ -217,6 +217,10 @@ func TestACAutomaton(t *testing.T) {
|
||||||
pattern: "vvgoogle.com",
|
pattern: "vvgoogle.com",
|
||||||
res: true,
|
res: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
pattern: "½",
|
||||||
|
res: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, test := range cases2Output {
|
for _, test := range cases2Output {
|
||||||
if m := ac.Match(test.pattern); m != test.res {
|
if m := ac.Match(test.pattern); m != test.res {
|
||||||
|
@ -224,7 +228,6 @@ func TestACAutomaton(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
cases3Input := []struct {
|
cases3Input := []struct {
|
||||||
pattern string
|
pattern string
|
||||||
|
|
Loading…
Reference in a new issue