Browse Source

asan: fix some bugs.

Nick Peng 1 year ago
parent
commit
655da274a0
6 changed files with 29 additions and 23 deletions
  1. 1 0
      src/dns_client.h
  2. 0 2
      src/dns_conf.c
  3. 24 18
      src/dns_server.c
  4. 1 1
      src/util.c
  5. 1 1
      test/cases/test-subnet.cc
  6. 2 1
      test/server.cc

+ 1 - 0
src/dns_client.h

@@ -108,6 +108,7 @@ struct client_dns_server_flag_udp {
 };
 
 struct client_dns_server_flag_mdns {
+	int padding;
 };
 
 struct client_dns_server_flag_tls {

+ 0 - 2
src/dns_conf.c

@@ -3024,7 +3024,6 @@ static int _config_bind_ip(int argc, char *argv[], DNS_BIND_TYPE type)
 	struct dns_bind_ip *bind_ip = NULL;
 	char *ip = NULL;
 	int opt = 0;
-	int optind = 0;
 	int optind_last = 0;
 	char group_name[DNS_GROUP_NAME_LEN];
 	const char *group = NULL;
@@ -4841,7 +4840,6 @@ static int _conf_domain_rule_no_ipalias(const char *domain)
 static int _conf_domain_rules(void *data, int argc, char *argv[])
 {
 	int opt = 0;
-	int optind = 0;
 	int optind_last = 0;
 	char domain[DNS_MAX_CONF_CNAME_LEN];
 	char *value = argv[1];

+ 24 - 18
src/dns_server.c

@@ -3582,26 +3582,29 @@ static int _dns_server_ip_rule_check(struct dns_request *request, struct dns_ip_
 		goto rule_not_found;
 	}
 
-	rule_flags = container_of(ip_rules->rules[IP_RULE_FLAGS], struct ip_rule_flags, head);
-	if (rule_flags != NULL) {
-		if (rule_flags->flags & IP_RULE_FLAG_BOGUS) {
-			request->rcode = DNS_RC_NXDOMAIN;
-			request->has_soa = 1;
-			request->force_soa = 1;
-			_dns_server_setup_soa(request);
-			goto nxdomain;
-		}
+	struct dns_ip_rule *rule = ip_rules->rules[IP_RULE_FLAGS];
+	if (rule != NULL) {
+		rule_flags = container_of(rule, struct ip_rule_flags, head);
+		if (rule_flags != NULL) {
+			if (rule_flags->flags & IP_RULE_FLAG_BOGUS) {
+				request->rcode = DNS_RC_NXDOMAIN;
+				request->has_soa = 1;
+				request->force_soa = 1;
+				_dns_server_setup_soa(request);
+				goto nxdomain;
+			}
 
-		/* blacklist-ip */
-		if (rule_flags->flags & IP_RULE_FLAG_BLACKLIST) {
-			if (result_flag & DNSSERVER_FLAG_BLACKLIST_IP) {
-				goto match;
+			/* blacklist-ip */
+			if (rule_flags->flags & IP_RULE_FLAG_BLACKLIST) {
+				if (result_flag & DNSSERVER_FLAG_BLACKLIST_IP) {
+					goto match;
+				}
 			}
-		}
 
-		/* ignore-ip */
-		if (rule_flags->flags & IP_RULE_FLAG_IP_IGNORE) {
-			goto skip;
+			/* ignore-ip */
+			if (rule_flags->flags & IP_RULE_FLAG_IP_IGNORE) {
+				goto skip;
+			}
 		}
 	}
 
@@ -4373,7 +4376,10 @@ static int _dns_server_get_answer(struct dns_server_post_context *context)
 					continue;
 				}
 
-				_dns_server_context_add_ip(context, addr_map->ip_addr);
+				if (addr_map != NULL) {
+					_dns_server_context_add_ip(context, addr_map->ip_addr);
+				}
+
 				if (request->has_ip == 1) {
 					continue;
 				}

+ 1 - 1
src/util.c

@@ -1064,7 +1064,7 @@ int netlink_get_neighbors(int family,
 			continue;
 		}
 
-		int nlh_len = len;
+		uint32_t nlh_len = len;
 		for (nlh = (struct nlmsghdr *)buf; NLMSG_OK(nlh, nlh_len); nlh = NLMSG_NEXT(nlh, nlh_len)) {
 			ndm = NLMSG_DATA(nlh);
 			struct rtattr *rta = RTM_RTA(ndm);

+ 1 - 1
test/cases/test-subnet.cc

@@ -493,7 +493,7 @@ TEST_F(SubNet, per_server)
 			return smartdns::SERVER_REQUEST_OK;
 		}
 
-		if (request->qtype = DNS_T_AAAA) {
+		if (request->qtype == DNS_T_AAAA) {
 			struct dns_opt_ecs ecs;
 			struct dns_rrs *rrs = NULL;
 			int rr_count = 0;

+ 2 - 1
test/server.cc

@@ -65,7 +65,7 @@ void MockServer::Stop()
 
 	if (fd_ > 0) {
 		close(fd_);
-		fd_;
+		fd_ = -1;;
 	}
 }
 
@@ -229,6 +229,7 @@ bool MockServer::GetAddr(const std::string &host, const std::string port, int ty
 
 	memcpy(addr, result->ai_addr, result->ai_addrlen);
 	*addrlen = result->ai_addrlen;
+	freeaddrinfo(result);
 	return true;
 errout:
 	if (result) {