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 <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2019-04-28 13:29:28 +02:00
parent f9feab492f
commit c0f70eda99
3 changed files with 11 additions and 6 deletions
+3 -3
View File
@@ -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)
+3
View File
@@ -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
/*------------------------------------------------------------------------*/
+5 -3
View File
@@ -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;