Skip to content

Commit

Permalink
Merge pull request #1197 from pi-hole/fix/rate_limit_crash
Browse files Browse the repository at this point in the history
Fix rare crashes when rate-limiting happens before queries are blocked
  • Loading branch information
DL6ER authored Oct 10, 2021
2 parents 301e97f + 449f782 commit 4c42246
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/dnsmasq_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static void check_pihole_PTR(char *domain);
static void _query_set_dnssec(queriesData *query, const enum dnssec_status dnssec, const char *file, const int line);

// Static blocking metadata
static const char *blockingreason = NULL;
static const char *blockingreason = "";
static union all_addr null_addrp = {{ 0 }};
static enum reply_type force_next_DNS_reply = REPLY_UNKNOWN;
static int last_regex_idx = -1;
Expand Down Expand Up @@ -295,11 +295,12 @@ size_t _FTL_make_answer(struct dns_header *header, char *limit, const size_t len
// Setup reply header
setup_reply(header, flags, *ede);

// Add NEG flag when replying with NXDOMAIN. This is necessary to get proper logging in pihole.log
// At the same time, we cannot add NEG before calling setup_reply() as it would, otherwise, result
// in an incorrect "nowhere to forward to" log entry (because setup_reply() checks for equality of
// flags instead of doing a bitmask comparison).
if(flags == F_NXDOMAIN)
// Add NEG flag when replying with NXDOMAIN or NODATA. This is necessary
// to get proper logging in pihole.log At the same time, we cannot add
// NEG before calling setup_reply() as it would, otherwise, result in an
// incorrect "nowhere to forward to" log entry (because setup_reply()
// checks for equality of flags instead of doing a bitmask comparison).
if(flags == F_NXDOMAIN || flags == F_NOERR)
flags |= F_NEG;

// Add flags according to current blocking mode
Expand Down Expand Up @@ -388,6 +389,7 @@ size_t _FTL_make_answer(struct dns_header *header, char *limit, const size_t len
else
{
// NODATA/NXDOMAIN
// gravity blocked abc.com is NODATA/NXDOMAIN
log_query(flags, name, NULL, (char*)blockingreason, 0);
}
}
Expand Down

0 comments on commit 4c42246

Please sign in to comment.