Skip to content

Commit

Permalink
Fix handling of NULL proto in sip_resolvehost()
Browse files Browse the repository at this point in the history
"proto" is not not mandatory (it may be NULL) as parameter, but there were cases where the code was assuming a not NULL proto variable.

Reported by Nick Altmann

(cherry picked from commit 29a048a)
  • Loading branch information
bogdan-iancu committed Dec 15, 2016
1 parent 3b9c2b9 commit d2f020b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions resolve.c
Expand Up @@ -1746,14 +1746,18 @@ struct hostent* sip_resolvehost( str* name, unsigned short* port,
struct rdata *head;
struct rdata *rd;
struct hostent* he;
unsigned short local_proto=PROTO_NONE;

if (dn)
*dn = 0;

if (proto==NULL)
proto = &local_proto;

/* check if it's an ip address */
if ( ((ip=str2ip(name))!=0) || ((ip=str2ip6(name))!=0) ){
/* we are lucky, this is an ip address */
if (proto && *proto==PROTO_NONE)
if (*proto==PROTO_NONE)
*proto = (is_sips)?PROTO_TLS:PROTO_UDP;
if (port && *port==0)
*port = protos[*proto].default_port;
Expand All @@ -1765,13 +1769,13 @@ struct hostent* sip_resolvehost( str* name, unsigned short* port,
/* have port -> no NAPTR, no SRV lookup, just A record lookup */
LM_DBG("has port -> do A record lookup!\n");
/* set default PROTO if not set */
if (proto && *proto==PROTO_NONE)
if (*proto==PROTO_NONE)
*proto = (is_sips)?PROTO_TLS:PROTO_UDP;
goto do_a;
}

/* no port... what about proto? */
if ( proto && (*proto)!=PROTO_NONE ) {
if ( (*proto)!=PROTO_NONE ) {
/* have proto, but no port -> do SRV lookup */
LM_DBG("no port, has proto -> do SRV lookup!\n");
if (is_sips && (*proto)!=PROTO_TLS) {
Expand Down

0 comments on commit d2f020b

Please sign in to comment.