dns_server: fix memory corrupt bug.

This commit is contained in:
Nick Peng
2023-07-17 21:47:14 +08:00
parent ffc331af21
commit 93a8b87c17
3 changed files with 25 additions and 11 deletions

View File

@@ -868,11 +868,11 @@ static struct dns_domain_rule *_config_domain_rule_get(const char *domain)
char domain_key[DNS_MAX_CONF_CNAME_LEN];
int len = 0;
if (len >= (int)sizeof(domain_key) - 1) {
len = strlen(domain);
if (len >= (int)sizeof(domain_key) - 2) {
return NULL;
}
len = strlen(domain);
reverse_string(domain_key, domain, len, 1);
domain_key[len] = '.';
len++;
@@ -893,7 +893,7 @@ static int _config_domain_rule_add(const char *domain, enum domain_rule type, vo
/* Reverse string, for suffix match */
len = strlen(domain);
if (len >= (int)sizeof(domain_key) - 1) {
if (len >= (int)sizeof(domain_key) - 2) {
tlog(TLOG_ERROR, "domain name %s too long", domain);
goto errout;
}