Skip to content

Commit

Permalink
Merge pull request #859 from pi-hole/fix/domainstring_validity
Browse files Browse the repository at this point in the history
Create and use a temporary copy of the domain string during the analysis
  • Loading branch information
DL6ER authored Aug 9, 2020
2 parents 905994e + 115ee1e commit 3414def
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/dnsmasq_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static bool _FTL_check_blocking(int queryID, int domainID, int clientID, const c
// Skip the entire chain of tests if we already know the answer for this
// particular client
unsigned char blockingStatus = dns_cache->blocking_status;
const char* domainstr = getstr(domain->domainpos);
char *domainstr = (char*)getstr(domain->domainpos);
switch(blockingStatus)
{
case UNKNOWN_BLOCKED:
Expand Down Expand Up @@ -252,8 +252,13 @@ static bool _FTL_check_blocking(int queryID, int domainID, int clientID, const c
return false;
}

// Check whitelist (exact + regex) for match
// Make a local copy of the domain string. The string memory may get
// reorganized in the following. We cannot expect domainstr to remain
// valid for all time.
domainstr = strdup(domainstr);
const char *blockedDomain = domainstr;

// Check whitelist (exact + regex) for match
query->whitelisted = in_whitelist(domainstr, clientID, client);

bool blockDomain = false;
Expand Down Expand Up @@ -299,6 +304,7 @@ static bool _FTL_check_blocking(int queryID, int domainID, int clientID, const c
dns_cache->blocking_status = query->whitelisted ? WHITELISTED : NOT_BLOCKED;
}

free(domainstr);
return blockDomain;
}

Expand Down

0 comments on commit 3414def

Please sign in to comment.