Jelajahi Sumber

core: dns - prevent queries for IPv4/6 address literals

- prevent A queries for IPv6 address literals or AAAA queries for IPv4
  address literals
- patch by Simon Perreault
Daniel-Constantin Mierla 12 tahun lalu
induk
melakukan
9e6f026809
1 mengubah file dengan 12 tambahan dan 0 penghapusan
  1. 12 0
      dns_cache.c

+ 12 - 0
dns_cache.c

@@ -1891,6 +1891,8 @@ inline static struct dns_hash_entry* dns_cache_do_request(str* name, int type)
 #endif /* USE_DNS_CACHE_STATS */
 
 	if (type==T_A){
+		if (str2ip6(name)!=0)
+			goto end;
 		if ((ip=str2ip(name))!=0){
 				e=dns_cache_mk_ip_entry(name, ip);
 				if (likely(e))
@@ -1900,6 +1902,8 @@ inline static struct dns_hash_entry* dns_cache_do_request(str* name, int type)
 	}
 #ifdef USE_IPV6
 	else if (type==T_AAAA){
+		if (str2ip(name)!=0)
+			goto end;
 		if ((ip=str2ip6(name))!=0){
 				e=dns_cache_mk_ip_entry(name, ip);
 				if (likely(e))
@@ -2465,6 +2469,8 @@ inline static struct hostent* dns_a_get_he(str* name)
 	struct hostent* he;
 
 	e=0;
+	if (str2ip6(name)!=0)
+		return 0;
 	if ((ip=str2ip(name))!=0){
 		return ip_addr2he(name, ip);
 	}
@@ -2489,6 +2495,8 @@ inline static struct hostent* dns_aaaa_get_he(str* name)
 	struct hostent* he;
 
 	e=0;
+	if (str2ip(name)!=0)
+		return 0;
 	if ((ip=str2ip6(name))!=0){
 		return ip_addr2he(name, ip);
 	}
@@ -2963,6 +2971,8 @@ inline static int dns_a_resolve( struct dns_hash_entry** e,
 	ret=-E_DNS_NO_IP;
 	if (*e==0){ /* do lookup */
 		/* if ip don't set *e */
+		if (str2ip6(name)!=0)
+			goto error;
 		if ((tmp=str2ip(name))!=0){
 			*ip=*tmp;
 			*rr_no=0;
@@ -3012,6 +3022,8 @@ inline static int dns_aaaa_resolve( struct dns_hash_entry** e,
 	ret=-E_DNS_NO_IP;
 	if (*e==0){ /* do lookup */
 		/* if ip don't set *e */
+		if (str2ip(name)!=0)
+			goto error;
 		if ((tmp=str2ip6(name))!=0){
 			*ip=*tmp;
 			*rr_no=0;