Fix regression in --rebind-domain-ok in 2.86

The 2.86 domain-match rewrite changed matching from
whole-labels to substring matching, so example.com
would match example.com and www.example.com, as before,
but also goodexample.com, which is a regression. This
restores the original behaviour.

Also restore the behaviour of --rebind-domain-ok=//
to match domains with onlt a single label and no dots.

Thanks to Sung Pae for reporting these bugs and supplying
an initial patch.
This commit is contained in:
Simon Kelley
2021-12-08 23:51:38 +00:00
parent 44a4643b62
commit 1176cd58c9

View File

@@ -153,11 +153,20 @@ static int domain_no_rebind(char *domain)
{
struct rebind_domain *rbd;
size_t tlen, dlen = strlen(domain);
char *dots = strchr(domain, '.');
/* Match whole labels only. Empty domain matches no dots (any single label) */
for (rbd = daemon->no_rebind; rbd; rbd = rbd->next)
if (dlen >= (tlen = strlen(rbd->domain)) && strcmp(rbd->domain, &domain[dlen - tlen]) == 0)
{
if (dlen >= (tlen = strlen(rbd->domain)) &&
hostname_isequal(rbd->domain, &domain[dlen - tlen]) &&
(dlen == tlen || domain[dlen - tlen - 1] == '.'))
return 1;
if (tlen == 0 && !dots)
return 1;
}
return 0;
}