diff --git a/src/dnsmasq_interface.c b/src/dnsmasq_interface.c index dc2285b7..4c31c9f2 100644 --- a/src/dnsmasq_interface.c +++ b/src/dnsmasq_interface.c @@ -1158,7 +1158,7 @@ static bool check_domain_blocked(const char *domain, const int clientID, // Check domain against blacklist regex filters // Skipped when the domain is whitelisted or blocked by exact blacklist or gravity - if(in_regex(domain, dns_cache, client-> id, REGEX_BLACKLIST) == FOUND) + if(in_regex(domain, dns_cache, client-> id, REGEX_BLACKLIST)) { // Set new status *new_status = QUERY_REGEX; @@ -1409,11 +1409,12 @@ static bool _FTL_check_blocking(int queryID, int domainID, int clientID, const c domainstr = strdup(domainstr); const char *blockedDomain = domainstr; - // Check whitelist (exact + regex) for match + // Check exact whitelist for match query->flags.whitelisted = in_whitelist(domainstr, dns_cache, client) == FOUND; + // If not found: Check regex whitelist for match if(!query->flags.whitelisted) - query->flags.whitelisted = in_regex(domainstr, dns_cache, client->id, REGEX_WHITELIST) == FOUND; + query->flags.whitelisted = in_regex(domainstr, dns_cache, client->id, REGEX_WHITELIST); // Check blacklist (exact + regex) and gravity for queried domain unsigned char new_status = QUERY_UNKNOWN; diff --git a/src/regex.c b/src/regex.c index 2a46dd70..e6753023 100644 --- a/src/regex.c +++ b/src/regex.c @@ -475,7 +475,7 @@ static int match_regex(const char *input, DNSCacheData* dns_cache, const int cli return match_idx; } -enum db_result in_regex(const char *domain, DNSCacheData *dns_cache, const int clientID, const enum regex_type regexid) +bool in_regex(const char *domain, DNSCacheData *dns_cache, const int clientID, const enum regex_type regexid) { // For performance reasons, the regex evaluations is executed only if the // exact whitelist lookup does not deliver a positive match. This is an @@ -487,10 +487,10 @@ enum db_result in_regex(const char *domain, DNSCacheData *dns_cache, const int c { // We found a match dns_cache->domainlist_id = regex_id; - return FOUND; + return true; } - return NOT_FOUND; + return false; } static void free_regex(void) diff --git a/src/regex_r.h b/src/regex_r.h index 6a63dcda..7ec979f7 100644 --- a/src/regex_r.h +++ b/src/regex_r.h @@ -44,7 +44,7 @@ typedef struct { } regexData; unsigned int get_num_regex(const enum regex_type regexid) __attribute__((pure)); -enum db_result in_regex(const char *domain, DNSCacheData *dns_cache, const int clientID, const enum regex_type regexid); +bool in_regex(const char *domain, DNSCacheData *dns_cache, const int clientID, const enum regex_type regexid); void allocate_regex_client_enabled(clientsData *client, const int clientID); void reload_per_client_regex(clientsData *client); void read_regex_from_database(void); diff --git a/src/shmem.c b/src/shmem.c index b0fcbc6a..648b3f44 100644 --- a/src/shmem.c +++ b/src/shmem.c @@ -272,14 +272,14 @@ size_t addstr(const char *input) return (shmSettings->next_str_pos - len); } -const char *getstr(const size_t pos) +const char *_getstr(const size_t pos, const char *func, const int line, const char *file) { // Only access the string memory if this memory region has already been set if(pos < shmSettings->next_str_pos) return &((const char*)shm_strings.ptr)[pos]; else { - logg("WARN: Tried to access %zu but next_str_pos is %u", pos, shmSettings->next_str_pos); + logg("WARN: Tried to access %zu in %s() (%s:%i) but next_str_pos is %u", pos, func, file, line, shmSettings->next_str_pos); return ""; } } @@ -337,7 +337,7 @@ static void remap_shm(void) } // Obtain SHMEM lock -void _lock_shm(const char* func, const int line, const char * file) +void _lock_shm(const char *func, const int line, const char *file) { if(config.debug & DEBUG_LOCKS) logg("Waiting for SHM lock in %s() (%s:%i)", func, file, line); diff --git a/src/shmem.h b/src/shmem.h index 9c59bed3..4532c6d2 100644 --- a/src/shmem.h +++ b/src/shmem.h @@ -102,7 +102,8 @@ void _unlock_log(const char* func, const int line, const char * file); bool init_shmem(bool create_new); void destroy_shmem(void); size_t addstr(const char *str); -const char *getstr(const size_t pos); +#define getstr(pos) _getstr(pos, __FUNCTION__, __LINE__, __FILE__) +const char *_getstr(const size_t pos, const char *func, const int line, const char *file); /** * Escapes a string by replacing special characters, such as spaces