Skip to content

Commit 7124ca1

Browse files
committed
dns_conf: fix bind option out-of-bounds issue
1 parent fc279fb commit 7124ca1

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/dns_conf.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -2999,9 +2999,12 @@ static int _bind_is_ip_valid(const char *ip)
29992999
struct sockaddr_storage addr;
30003000
socklen_t addr_len = sizeof(addr);
30013001
char ip_check[MAX_IP_LEN];
3002-
int port_check = 0;
3002+
int port_check = -1;
30033003

30043004
if (parse_ip(ip, ip_check, &port_check) != 0) {
3005+
if (port_check != -1 && ip_check[0] == '\0') {
3006+
return 0;
3007+
}
30053008
return -1;
30063009
}
30073010

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

30553058
ip = argv[1];
3056-
if (index >= DNS_MAX_SERVERS) {
3059+
if (index >= DNS_MAX_BIND_IP) {
30573060
tlog(TLOG_WARN, "exceeds max server number, %s", ip);
30583061
return 0;
30593062
}
@@ -3073,7 +3076,7 @@ static int _config_bind_ip(int argc, char *argv[], DNS_BIND_TYPE type)
30733076
continue;
30743077
}
30753078

3076-
tlog(TLOG_WARN, "Bind server %s, type %d, already configured, skip.", ip, type);
3079+
tlog(TLOG_WARN, "bind server %s, type %d, already configured, skip.", ip, type);
30773080
return 0;
30783081
}
30793082

src/dns_conf.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
extern "C" {
3535
#endif
3636

37-
#define DNS_MAX_BIND_IP 16
37+
#define DNS_MAX_BIND_IP 32
3838
#define DNS_MAX_SERVERS 64
3939
#define DNS_MAX_SERVER_NAME_LEN 128
4040
#define DNS_MAX_PTR_LEN 128

src/dns_server.c

+2
Original file line numberDiff line numberDiff line change
@@ -8973,6 +8973,8 @@ static int _dns_server_socket(void)
89738973

89748974
for (i = 0; i < dns_conf_bind_ip_num; i++) {
89758975
struct dns_bind_ip *bind_ip = &dns_conf_bind_ip[i];
8976+
tlog(TLOG_INFO, "bind ip %s, type %d", bind_ip->ip, bind_ip->type);
8977+
89768978
switch (bind_ip->type) {
89778979
case DNS_BIND_TYPE_UDP:
89788980
if (_dns_server_socket_udp(bind_ip) != 0) {

0 commit comments

Comments
 (0)