mirror of
https://github.com/tailscale/tailscale.git
synced 2024-12-05 07:55:36 +00:00
net/dns/resolvconffile: fix handling of multiple search domains
Fixes #6875
Change-Id: I57eb9312c9a1c81792ce2b5a0a0f254213b05df2
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
(cherry picked from commit ea70aa3d98
)
This commit is contained in:
parent
e32d5af73f
commit
48d5b7f89c
@ -83,17 +83,26 @@ func Parse(r io.Reader) (*Config, error) {
|
||||
}
|
||||
|
||||
if s, ok := strs.CutPrefix(line, "search"); ok {
|
||||
domain := strings.TrimSpace(s)
|
||||
if len(domain) == len(s) {
|
||||
domains := strings.TrimSpace(s)
|
||||
if len(domains) == len(s) {
|
||||
// No leading space?!
|
||||
return nil, fmt.Errorf("missing space after \"domain\" in %q", line)
|
||||
return nil, fmt.Errorf("missing space after \"search\" in %q", line)
|
||||
}
|
||||
fqdn, err := dnsname.ToFQDN(domain)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parsing search domains %q: %w", line, err)
|
||||
for len(domains) > 0 {
|
||||
domain := domains
|
||||
i := strings.IndexAny(domain, " \t")
|
||||
if i != -1 {
|
||||
domain = domain[:i]
|
||||
domains = strings.TrimSpace(domains[i+1:])
|
||||
} else {
|
||||
domains = ""
|
||||
}
|
||||
fqdn, err := dnsname.ToFQDN(domain)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parsing search domain %q in %q: %w", domain, line, err)
|
||||
}
|
||||
config.SearchDomains = append(config.SearchDomains, fqdn)
|
||||
}
|
||||
config.SearchDomains = append(config.SearchDomains, fqdn)
|
||||
continue
|
||||
}
|
||||
}
|
||||
return config, nil
|
||||
|
@ -57,6 +57,31 @@ func TestParse(t *testing.T) {
|
||||
},
|
||||
{in: `searchtailsacle.com`, wantErr: true},
|
||||
{in: `search`, wantErr: true},
|
||||
|
||||
// Issue 6875: there can be multiple search domains, and even if they're
|
||||
// over 253 bytes long total.
|
||||
{
|
||||
in: "search search-01.example search-02.example search-03.example search-04.example search-05.example search-06.example search-07.example search-08.example search-09.example search-10.example search-11.example search-12.example search-13.example search-14.example search-15.example\n",
|
||||
want: &Config{
|
||||
SearchDomains: []dnsname.FQDN{
|
||||
"search-01.example.",
|
||||
"search-02.example.",
|
||||
"search-03.example.",
|
||||
"search-04.example.",
|
||||
"search-05.example.",
|
||||
"search-06.example.",
|
||||
"search-07.example.",
|
||||
"search-08.example.",
|
||||
"search-09.example.",
|
||||
"search-10.example.",
|
||||
"search-11.example.",
|
||||
"search-12.example.",
|
||||
"search-13.example.",
|
||||
"search-14.example.",
|
||||
"search-15.example.",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
Loading…
Reference in New Issue
Block a user