Module: kamailio Branch: master Commit: aff1dcd3dc63c0fe124fc138d553da0723c615a8 URL: https://github.com/kamailio/kamailio/commit/aff1dcd3dc63c0fe124fc138d553da07...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2014-12-22T21:41:53+01:00
core: safety checks on proto variable for dsn resolving
- avoid crashes if functions used inadequately with a null pointer
---
Modified: dns_cache.c Modified: msg_translator.c
---
Diff: https://github.com/kamailio/kamailio/commit/aff1dcd3dc63c0fe124fc138d553da07... Patch: https://github.com/kamailio/kamailio/commit/aff1dcd3dc63c0fe124fc138d553da07...
---
diff --git a/dns_cache.c b/dns_cache.c index 285c6ad..2e963a8 100644 --- a/dns_cache.c +++ b/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) { diff --git a/msg_translator.c b/msg_translator.c index df1a753..8bca35f 100644 --- a/msg_translator.c +++ b/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)