Browse code

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 authored on 21/02/2013 09:40:07
Showing 1 changed files
... ...
@@ -1891,6 +1891,8 @@ inline static struct dns_hash_entry* dns_cache_do_request(str* name, int type)
1891 1891
 #endif /* USE_DNS_CACHE_STATS */
1892 1892
 
1893 1893
 	if (type==T_A){
1894
+		if (str2ip6(name)!=0)
1895
+			goto end;
1894 1896
 		if ((ip=str2ip(name))!=0){
1895 1897
 				e=dns_cache_mk_ip_entry(name, ip);
1896 1898
 				if (likely(e))
... ...
@@ -1900,6 +1902,8 @@ inline static struct dns_hash_entry* dns_cache_do_request(str* name, int type)
1900 1900
 	}
1901 1901
 #ifdef USE_IPV6
1902 1902
 	else if (type==T_AAAA){
1903
+		if (str2ip(name)!=0)
1904
+			goto end;
1903 1905
 		if ((ip=str2ip6(name))!=0){
1904 1906
 				e=dns_cache_mk_ip_entry(name, ip);
1905 1907
 				if (likely(e))
... ...
@@ -2465,6 +2469,8 @@ inline static struct hostent* dns_a_get_he(str* name)
2465 2465
 	struct hostent* he;
2466 2466
 
2467 2467
 	e=0;
2468
+	if (str2ip6(name)!=0)
2469
+		return 0;
2468 2470
 	if ((ip=str2ip(name))!=0){
2469 2471
 		return ip_addr2he(name, ip);
2470 2472
 	}
... ...
@@ -2489,6 +2495,8 @@ inline static struct hostent* dns_aaaa_get_he(str* name)
2489 2489
 	struct hostent* he;
2490 2490
 
2491 2491
 	e=0;
2492
+	if (str2ip(name)!=0)
2493
+		return 0;
2492 2494
 	if ((ip=str2ip6(name))!=0){
2493 2495
 		return ip_addr2he(name, ip);
2494 2496
 	}
... ...
@@ -2963,6 +2971,8 @@ inline static int dns_a_resolve( struct dns_hash_entry** e,
2963 2963
 	ret=-E_DNS_NO_IP;
2964 2964
 	if (*e==0){ /* do lookup */
2965 2965
 		/* if ip don't set *e */
2966
+		if (str2ip6(name)!=0)
2967
+			goto error;
2966 2968
 		if ((tmp=str2ip(name))!=0){
2967 2969
 			*ip=*tmp;
2968 2970
 			*rr_no=0;
... ...
@@ -3012,6 +3022,8 @@ inline static int dns_aaaa_resolve( struct dns_hash_entry** e,
3012 3012
 	ret=-E_DNS_NO_IP;
3013 3013
 	if (*e==0){ /* do lookup */
3014 3014
 		/* if ip don't set *e */
3015
+		if (str2ip(name)!=0)
3016
+			goto error;
3015 3017
 		if ((tmp=str2ip6(name))!=0){
3016 3018
 			*ip=*tmp;
3017 3019
 			*rr_no=0;