Skip to content

Commit dc91b09

Browse files
authored
Merge pull request #11 from shadow3x3x3/fix-wildcard-records
fix an out of range wildcard query
2 parents 0de2288 + e808984 commit dc91b09

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

mysql.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,25 @@ func (handler *CoreDNSMySql) findRecord(zone string, name string, types ...strin
5959

6060
// findWildcardRecords attempts to find wildcard records
6161
// recursively until it finds matching records.
62-
// e.g. zone: example.com
63-
// x.y.z.example.com -> *.y.z.example.com -> *.z.example.com -> *.example.com
62+
// e.g. x.y.z -> *.y.z -> *.z -> *
6463
func (handler *CoreDNSMySql) findWildcardRecords(zone string, name string, types ...string) ([]*Record, error) {
65-
const dot = "."
64+
const (
65+
wildcard = "*"
66+
wildcardPrefix = wildcard + "."
67+
)
6668

67-
subNames := strings.Split(name, dot)
68-
nextSubNames := subNames[1:]
69-
if subNames[0] == "*" {
70-
nextSubNames = subNames[2:]
69+
if name == wildcard {
70+
return nil, nil
71+
}
72+
73+
name = strings.TrimPrefix(name, wildcardPrefix)
74+
75+
target := wildcard
76+
i, shot := dns.NextLabel(name, 0)
77+
if !shot {
78+
target = wildcardPrefix + name[i:]
7179
}
7280

73-
names := append([]string{"*"}, nextSubNames...)
74-
target := strings.Join(names, dot)
7581
return handler.findRecord(zone, target, types...)
7682
}
7783

0 commit comments

Comments
 (0)