From 1ad636baa63cfe029c84235986626c17e4ff33cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20R=C3=BChsen?= Date: Wed, 17 Jan 2018 15:50:48 +0100 Subject: [PATCH] * src/host.c (sufmatch): Fix to domain matching --- src/host.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/host.c b/src/host.c index 2ddae328..d337cc7c 100644 --- a/src/host.c +++ b/src/host.c @@ -1017,18 +1017,25 @@ sufmatch (const char **list, const char *what) int i, j, k, lw; lw = strlen (what); + for (i = 0; list[i]; i++) { - if (list[i][0] == '\0') - continue; + j = strlen (list[i]); + if (lw < j) + continue; /* what is no (sub)domain of list[i] */ - for (j = strlen (list[i]), k = lw; j >= 0 && k >= 0; j--, k--) + for (k = lw; j >= 0 && k >= 0; j--, k--) if (c_tolower (list[i][j]) != c_tolower (what[k])) break; - /* The domain must be first to reach to beginning. */ - if (j == -1) + + /* Domain or subdomain match + * k == -1: exact match + * k >= 0 && what[k] == '.': subdomain match + */ + if (j == -1 && (k == -1 || what[k] == '.')) return true; } + return false; } -- 2.15.1