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 1902
 	}
1901 1903
 #ifdef USE_IPV6
1902 1904
 	else if (type==T_AAAA){
1905
+		if (str2ip(name)!=0)
1906
+			goto end;
1903 1907
 		if ((ip=str2ip6(name))!=0){
1904 1908
 				e=dns_cache_mk_ip_entry(name, ip);
1905 1909
 				if (likely(e))
... ...
@@ -2465,6 +2469,8 @@ inline static struct hostent* dns_a_get_he(str* name)
2465 2469
 	struct hostent* he;
2466 2470
 
2467 2471
 	e=0;
2472
+	if (str2ip6(name)!=0)
2473
+		return 0;
2468 2474
 	if ((ip=str2ip(name))!=0){
2469 2475
 		return ip_addr2he(name, ip);
2470 2476
 	}
... ...
@@ -2489,6 +2495,8 @@ inline static struct hostent* dns_aaaa_get_he(str* name)
2489 2495
 	struct hostent* he;
2490 2496
 
2491 2497
 	e=0;
2498
+	if (str2ip(name)!=0)
2499
+		return 0;
2492 2500
 	if ((ip=str2ip6(name))!=0){
2493 2501
 		return ip_addr2he(name, ip);
2494 2502
 	}
... ...
@@ -2963,6 +2971,8 @@ inline static int dns_a_resolve( struct dns_hash_entry** e,
2963 2971
 	ret=-E_DNS_NO_IP;
2964 2972
 	if (*e==0){ /* do lookup */
2965 2973
 		/* if ip don't set *e */
2974
+		if (str2ip6(name)!=0)
2975
+			goto error;
2966 2976
 		if ((tmp=str2ip(name))!=0){
2967 2977
 			*ip=*tmp;
2968 2978
 			*rr_no=0;
... ...
@@ -3012,6 +3022,8 @@ inline static int dns_aaaa_resolve( struct dns_hash_entry** e,
3012 3022
 	ret=-E_DNS_NO_IP;
3013 3023
 	if (*e==0){ /* do lookup */
3014 3024
 		/* if ip don't set *e */
3025
+		if (str2ip(name)!=0)
3026
+			goto error;
3015 3027
 		if ((tmp=str2ip6(name))!=0){
3016 3028
 			*ip=*tmp;
3017 3029
 			*rr_no=0;