From c0f70eda99bc8a847a2b7d138a2cd49250790588 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 28 Apr 2019 13:29:28 +0200 Subject: [PATCH] Use strcmp() instead of strstr() when comparing the source of a cached DNS entry to our gravity and blacklist table names. This ensures that only exact matches to these table names are qualified as officially blocked configurations. Previously, also config files such as /home/somebody/my.gravity.list would have been shown as "Blocked (gravity)". While this might have been a nice side-effect it also was kind of undefined behavior which is now corrected. Signed-off-by: DL6ER --- dnsmasq/cache.c | 6 +++--- dnsmasq/dnsmasq.h | 3 +++ dnsmasq_interface.c | 8 +++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/dnsmasq/cache.c b/dnsmasq/cache.c index f43cfb48..9b0f9772 100644 --- a/dnsmasq/cache.c +++ b/dnsmasq/cache.c @@ -1689,11 +1689,11 @@ char *record_source(unsigned int index) return HOSTSFILE; /*----- Pi-hole modification -----*/ else if (index == SRC_REGEX) - return "regex"; + return SRC_REGEX_NAME; else if (index == SRC_GRAVITY) - return "gravity"; + return SRC_GRAVITY_NAME; else if (index == SRC_BLACK) - return "blacklist"; + return SRC_BLACK_NAME; /*--------------------------------*/ for (ah = daemon->addn_hosts; ah; ah = ah->next) diff --git a/dnsmasq/dnsmasq.h b/dnsmasq/dnsmasq.h index 94534afe..e096dfcf 100644 --- a/dnsmasq/dnsmasq.h +++ b/dnsmasq/dnsmasq.h @@ -496,8 +496,11 @@ struct crec { // ID 5 will be used for the blacklist table // ID 6 will be used as starting index for any Additional Hosts (AH) files #define SRC_REGEX 3 +#define SRC_REGEX_NAME "regex" #define SRC_GRAVITY 4 +#define SRC_GRAVITY_NAME "gravity" #define SRC_BLACK 5 +#define SRC_BLACK_NAME "blacklist" #define SRC_AH 6 /*------------------------------------------------------------------------*/ diff --git a/dnsmasq_interface.c b/dnsmasq_interface.c index 327c7c5e..4e300d0a 100644 --- a/dnsmasq_interface.c +++ b/dnsmasq_interface.c @@ -734,7 +734,9 @@ void _FTL_cache(const unsigned int flags, const char *name, const struct all_add (flags & F_REVERSE) || (flags & F_RRNAME)) { - // List data: /etc/pihole/gravity.list, /etc/pihole/black.list, /etc/pihole/local.list, etc. + // Local list: /etc/hosts, /etc/pihole/local.list, etc. + // or + // blocked domain from gravity database // or // DHCP server reply // or @@ -746,9 +748,9 @@ void _FTL_cache(const unsigned int flags, const char *name, const struct all_add unsigned char requesttype = 0; if(flags & F_HOSTS) { - if(arg != NULL && strstr(arg, "gravity") != NULL) + if(arg != NULL && strcmp(arg, "gravity") == 0) requesttype = QUERY_GRAVITY; - else if(arg != NULL && strstr(arg, "blacklist") != NULL) + else if(arg != NULL && strcmp(arg, "blacklist") == 0) requesttype = QUERY_BLACKLIST; else // local.list, hostname.list, /etc/hosts and others requesttype = QUERY_CACHE;