Browse code

core: safety checks on proto variable for dsn resolving

- avoid crashes if functions used inadequately with a null pointer

Daniel-Constantin Mierla authored on 22/12/2014 20:41:53
Showing 2 changed files
... ...
@@ -2808,7 +2808,11 @@ struct hostent* dns_naptr_sip_resolvehost(str* name, unsigned short* port,
2808 2808
 	char origproto;
2809 2809
 	str srv_name;
2810 2810
 
2811
-	origproto=*proto;
2811
+	if(proto) {
2812
+		origproto=*proto;
2813
+	} else {
2814
+		origproto=PROTO_NONE;
2815
+	}
2812 2816
 	he=0;
2813 2817
 	if (dns_hash==0){ /* not init => use normal, non-cached version */
2814 2818
 		LM_WARN("called before dns cache initialization\n");
... ...
@@ -2848,7 +2852,7 @@ struct hostent* dns_naptr_sip_resolvehost(str* name, unsigned short* port,
2848 2848
 		dns_hash_put(e);
2849 2849
 	}
2850 2850
 naptr_not_found:
2851
-	*proto = origproto;
2851
+	if(proto) *proto = origproto;
2852 2852
 	he = no_naptr_srv_sip_resolvehost(name,port,proto);
2853 2853
 	/* fallback all the way down to A/AAAA */
2854 2854
 	if (he==0) {
... ...
@@ -197,6 +197,7 @@ static int check_via_address(struct ip_addr* ip, str *name,
197 197
 	int i;
198 198
 	char* s;
199 199
 	int len;
200
+	char lproto;
200 201
 
201 202
 	/* maybe we are lucky and name it's an ip */
202 203
 	s=ip_addr2a(ip);
... ...
@@ -229,7 +230,8 @@ static int check_via_address(struct ip_addr* ip, str *name,
229 229
 	if (resolver&DO_DNS){
230 230
 		DBG("check_via_address: doing dns lookup\n");
231 231
 		/* try all names ips */
232
-		he=sip_resolvehost(name, &port, 0); /* don't use naptr */
232
+		lproto = PROTO_NONE;
233
+		he=sip_resolvehost(name, &port, &lproto); /* don't use naptr */
233 234
 		if (he && ip->af==he->h_addrtype){
234 235
 			for(i=0;he && he->h_addr_list[i];i++){
235 236
 				if ( memcmp(&he->h_addr_list[i], ip->u.addr, ip->len)==0)