Skip to content

Commit

Permalink
core: safety checks on proto variable for dsn resolving
Browse files Browse the repository at this point in the history
- avoid crashes if functions used inadequately with a null pointer

(cherry picked from commit aff1dcd)
  • Loading branch information
miconda committed Jan 8, 2015
1 parent b97ee87 commit 813b256
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions dns_cache.c
Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion msg_translator.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 813b256

Please sign in to comment.