Browse Source

core: safety checks on proto variable for dsn resolving

- avoid crashes if functions used inadequately with a null pointer
Daniel-Constantin Mierla 10 năm trước cách đây
mục cha
commit
aff1dcd3dc
2 tập tin đã thay đổi với 9 bổ sung3 xóa
  1. 6 2
      dns_cache.c
  2. 3 1
      msg_translator.c

+ 6 - 2
dns_cache.c

@@ -2808,7 +2808,11 @@ struct hostent* dns_naptr_sip_resolvehost(str* name, unsigned short* port,
 	char origproto;
 	str srv_name;
 
-	origproto=*proto;
+	if(proto) {
+		origproto=*proto;
+	} else {
+		origproto=PROTO_NONE;
+	}
 	he=0;
 	if (dns_hash==0){ /* not init => use normal, non-cached version */
 		LM_WARN("called before dns cache initialization\n");
@@ -2848,7 +2852,7 @@ struct hostent* dns_naptr_sip_resolvehost(str* name, unsigned short* port,
 		dns_hash_put(e);
 	}
 naptr_not_found:
-	*proto = origproto;
+	if(proto) *proto = origproto;
 	he = no_naptr_srv_sip_resolvehost(name,port,proto);
 	/* fallback all the way down to A/AAAA */
 	if (he==0) {

+ 3 - 1
msg_translator.c

@@ -197,6 +197,7 @@ static int check_via_address(struct ip_addr* ip, str *name,
 	int i;
 	char* s;
 	int len;
+	char lproto;
 
 	/* maybe we are lucky and name it's an ip */
 	s=ip_addr2a(ip);
@@ -229,7 +230,8 @@ static int check_via_address(struct ip_addr* ip, str *name,
 	if (resolver&DO_DNS){
 		DBG("check_via_address: doing dns lookup\n");
 		/* try all names ips */
-		he=sip_resolvehost(name, &port, 0); /* don't use naptr */
+		lproto = PROTO_NONE;
+		he=sip_resolvehost(name, &port, &lproto); /* don't use naptr */
 		if (he && ip->af==he->h_addrtype){
 			for(i=0;he && he->h_addr_list[i];i++){
 				if ( memcmp(&he->h_addr_list[i], ip->u.addr, ip->len)==0)