Skip to content

Commit

Permalink
Update blackwhitelist.c
Browse files Browse the repository at this point in the history
  • Loading branch information
SashaXser authored Feb 4, 2024
1 parent bf5bedd commit a8517af
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/blackwhitelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,26 +85,25 @@ int blackwhitelist_load_list(const char *filename) {
}

int blackwhitelist_check_hostname(const char *host_addr, size_t host_len) {
char current_host[HOST_MAXLEN + 1];
char *tokenized_host = NULL;

if (host_len > HOST_MAXLEN) return FALSE;
if (host_addr && host_len) {
memcpy(current_host, host_addr, host_len);
current_host[host_len] = '\0';
}
if (!host_addr || !host_len) return FALSE;

if (check_get_hostname(current_host))
return TRUE;
// Start by checking the full domain and each subdomain
const char *tokenized_host = host_addr;
const char *end = host_addr + host_len;

tokenized_host = strchr(current_host, '.');
while (tokenized_host != NULL && tokenized_host < (current_host + HOST_MAXLEN)) {
/* Search hostname only if there is next token */
if (strchr(tokenized_host + 1, '.') && check_get_hostname(tokenized_host + 1))
// Check each subdomain starting from the TLD
while (tokenized_host < end) {
if (check_get_hostname(tokenized_host)) {
return TRUE;
tokenized_host = strchr(tokenized_host + 1, '.');
}

// Move to the next subdomain
tokenized_host = strchr(tokenized_host, '.');
if (!tokenized_host) break; // No more subdomains
tokenized_host++; // Skip the dot
}

debug("____blackwhitelist_check_hostname FALSE: host %s\n", current_host);
debug("____blackwhitelist_check_hostname FALSE: host %.*s\n", (int)host_len, host_addr);
return FALSE;
}

0 comments on commit a8517af

Please sign in to comment.