Fix problems with upper-case in domain-match.

The domain-match rewrite didn't take into account
that domain names are case-insensitive, so things like

--address=/Example.com/.....

didn't work correctly.
This commit is contained in:
Simon Kelley
2021-11-28 18:39:42 +00:00
parent 9560658c5b
commit e3093b532c
4 changed files with 15 additions and 6 deletions

View File

@@ -1376,6 +1376,7 @@ void safe_pipe(int *fd, int read_noblock);
void *whine_malloc(size_t size); void *whine_malloc(size_t size);
int sa_len(union mysockaddr *addr); int sa_len(union mysockaddr *addr);
int sockaddr_isequal(const union mysockaddr *s1, const union mysockaddr *s2); int sockaddr_isequal(const union mysockaddr *s1, const union mysockaddr *s2);
int hostname_order(const char *a, const char *b);
int hostname_isequal(const char *a, const char *b); int hostname_isequal(const char *a, const char *b);
int hostname_issubdomain(char *a, char *b); int hostname_issubdomain(char *a, char *b);
time_t dnsmasq_time(void); time_t dnsmasq_time(void);

View File

@@ -494,7 +494,7 @@ static int order(char *qdomain, size_t qlen, struct server *serv)
if (qlen > dlen) if (qlen > dlen)
return -1; return -1;
return strcmp(qdomain, serv->domain); return hostname_order(qdomain, serv->domain);
} }
static int order_servers(struct server *s1, struct server *s2) static int order_servers(struct server *s1, struct server *s2)

View File

@@ -170,8 +170,8 @@ static int forward_query(int udpfd, union mysockaddr *udpaddr,
unsigned int fwd_flags = 0; unsigned int fwd_flags = 0;
int is_dnssec = forward && (forward->flags & (FREC_DNSKEY_QUERY | FREC_DS_QUERY)); int is_dnssec = forward && (forward->flags & (FREC_DNSKEY_QUERY | FREC_DS_QUERY));
struct server *master; struct server *master;
unsigned int gotname = extract_request(header, plen, daemon->namebuff, NULL);
void *hash = hash_questions(header, plen, daemon->namebuff); void *hash = hash_questions(header, plen, daemon->namebuff);
unsigned int gotname = extract_request(header, plen, daemon->namebuff, NULL);
unsigned char *oph = find_pseudoheader(header, plen, NULL, NULL, NULL, NULL); unsigned char *oph = find_pseudoheader(header, plen, NULL, NULL, NULL, NULL);
int old_src = 0, old_reply = 0; int old_src = 0, old_reply = 0;
int first, last, start = 0; int first, last, start = 0;

View File

@@ -367,7 +367,7 @@ int sa_len(union mysockaddr *addr)
} }
/* don't use strcasecmp and friends here - they may be messed up by LOCALE */ /* don't use strcasecmp and friends here - they may be messed up by LOCALE */
int hostname_isequal(const char *a, const char *b) int hostname_order(const char *a, const char *b)
{ {
unsigned int c1, c2; unsigned int c1, c2;
@@ -380,11 +380,19 @@ int hostname_isequal(const char *a, const char *b)
if (c2 >= 'A' && c2 <= 'Z') if (c2 >= 'A' && c2 <= 'Z')
c2 += 'a' - 'A'; c2 += 'a' - 'A';
if (c1 != c2) if (c1 < c2)
return 0; return -1;
else if (c1 > c2)
return 1;
} while (c1); } while (c1);
return 1; return 0;
}
int hostname_isequal(const char *a, const char *b)
{
return hostname_order(a, b) == 0;
} }
/* is b equal to or a subdomain of a return 2 for equal, 1 for subdomain */ /* is b equal to or a subdomain of a return 2 for equal, 1 for subdomain */