Skip to content

Commit

Permalink
dns_conf: fix bind option out-of-bounds issue
Browse files Browse the repository at this point in the history
  • Loading branch information
pymumu committed Mar 13, 2024
1 parent fc279fb commit 7124ca1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/dns_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2999,9 +2999,12 @@ static int _bind_is_ip_valid(const char *ip)
struct sockaddr_storage addr;
socklen_t addr_len = sizeof(addr);
char ip_check[MAX_IP_LEN];
int port_check = 0;
int port_check = -1;

if (parse_ip(ip, ip_check, &port_check) != 0) {
if (port_check != -1 && ip_check[0] == '\0') {
return 0;
}
return -1;
}

Expand Down Expand Up @@ -3048,12 +3051,12 @@ static int _config_bind_ip(int argc, char *argv[], DNS_BIND_TYPE type)
};
/* clang-format on */
if (argc <= 1) {
tlog(TLOG_ERROR, "invalid parameter.");
tlog(TLOG_ERROR, "bind: invalid parameter.");
goto errout;
}

ip = argv[1];
if (index >= DNS_MAX_SERVERS) {
if (index >= DNS_MAX_BIND_IP) {
tlog(TLOG_WARN, "exceeds max server number, %s", ip);
return 0;
}
Expand All @@ -3073,7 +3076,7 @@ static int _config_bind_ip(int argc, char *argv[], DNS_BIND_TYPE type)
continue;
}

tlog(TLOG_WARN, "Bind server %s, type %d, already configured, skip.", ip, type);
tlog(TLOG_WARN, "bind server %s, type %d, already configured, skip.", ip, type);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/dns_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
extern "C" {
#endif

#define DNS_MAX_BIND_IP 16
#define DNS_MAX_BIND_IP 32
#define DNS_MAX_SERVERS 64
#define DNS_MAX_SERVER_NAME_LEN 128
#define DNS_MAX_PTR_LEN 128
Expand Down
2 changes: 2 additions & 0 deletions src/dns_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -8973,6 +8973,8 @@ static int _dns_server_socket(void)

for (i = 0; i < dns_conf_bind_ip_num; i++) {
struct dns_bind_ip *bind_ip = &dns_conf_bind_ip[i];
tlog(TLOG_INFO, "bind ip %s, type %d", bind_ip->ip, bind_ip->type);

switch (bind_ip->type) {
case DNS_BIND_TYPE_UDP:
if (_dns_server_socket_udp(bind_ip) != 0) {
Expand Down

0 comments on commit 7124ca1

Please sign in to comment.