Skip to content

Commit

Permalink
Proper handle the case of no usrloc domain registered.
Browse files Browse the repository at this point in the history
Prevent get_next_udomain() crashing if there are no usrloc domains registered (reported by Qasim Akhan on users mailing list.
Do not enable the pinging support in nathelper if usrloc has no registered domains.
  • Loading branch information
bogdan-iancu committed Jun 3, 2016
1 parent 29995e4 commit 8f0c677
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
49 changes: 29 additions & 20 deletions modules/nathelper/nathelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,20 +491,6 @@ mod_init(void)
rcv_avp_type = 0;
}

if (force_socket_str) {
socket_str.s=force_socket_str;
socket_str.len=strlen(socket_str.s);
force_socket=grep_sock_info(&socket_str,0,0);
}

/* create raw socket? */
if (natping_socket && natping_socket[0]) {
if (get_natping_socket( natping_socket, &raw_ip, &raw_port)!=0)
return -1;
if (init_raw_socket() < 0)
return -1;
}

if (nortpproxy_str.s==NULL || nortpproxy_str.s[0]==0) {
nortpproxy_str.len = 0;
nortpproxy_str.s = NULL;
Expand All @@ -517,6 +503,9 @@ mod_init(void)
nortpproxy_str.s = NULL;
}

/* enable all the pinging stuff only if pinging interval is set and
* if we have at least one domain in the usrloc (otherwise there is
* nothing to ping) */
if (natping_interval > 0) {
bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0);
if (!bind_usrloc) {
Expand All @@ -528,6 +517,26 @@ mod_init(void)
return -1;
}

if ( ul.get_next_udomain(NULL)==NULL ) {
/* no usrloc domains, nothing to ping, so abort enabling
* the pinging support */
goto after_pinging;
}

if (force_socket_str) {
socket_str.s=force_socket_str;
socket_str.len=strlen(socket_str.s);
force_socket=grep_sock_info(&socket_str,0,0);
}

/* create raw socket? */
if (natping_socket && natping_socket[0]) {
if (get_natping_socket( natping_socket, &raw_ip, &raw_port)!=0)
return -1;
if (init_raw_socket() < 0)
return -1;
}

natping_state =(unsigned int *) shm_malloc(sizeof(unsigned int));
if (!natping_state) {
LM_ERR("no shmem left\n");
Expand All @@ -547,13 +556,11 @@ mod_init(void)
}

fix_flag_name(sipping_flag_str, sipping_flag);
sipping_flag = get_flag_id_by_name(FLAG_TYPE_BRANCH, sipping_flag_str);

sipping_flag=get_flag_id_by_name(FLAG_TYPE_BRANCH, sipping_flag_str);
sipping_flag = (sipping_flag==-1)?0:(1<<sipping_flag);

fix_flag_name(rm_on_to_flag_str, rm_on_to_flag);
rm_on_to_flag = get_flag_id_by_name(FLAG_TYPE_BRANCH, rm_on_to_flag_str);

rm_on_to_flag=get_flag_id_by_name(FLAG_TYPE_BRANCH, rm_on_to_flag_str);
rm_on_to_flag = (rm_on_to_flag==-1)?0:(1<<rm_on_to_flag);

/* set reply function if SIP natping is enabled */
Expand All @@ -579,8 +586,8 @@ mod_init(void)
}

if (REMOVE_ON_TIMEOUT &&
register_timer("pg-chk-timer", ping_checker_timer,
NULL, ping_checker_interval, TIMER_FLAG_DELAY_ON_DELAY) < 0) {
register_timer("pg-chk-timer", ping_checker_timer,
NULL, ping_checker_interval, TIMER_FLAG_DELAY_ON_DELAY) < 0) {
LM_ERR("failed to register ping checker timer\n");
return -1;
}
Expand All @@ -603,6 +610,8 @@ mod_init(void)
}
}

after_pinging:

/* Prepare 1918/6598 networks list */
for (i = 0; nets_1918[i].cnetaddr != NULL; i++) {
if (inet_aton(nets_1918[i].cnetaddr, &addr) != 1)
Expand Down
5 changes: 5 additions & 0 deletions modules/usrloc/dlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ udomain_t* get_next_udomain(udomain_t *_d)
{
dlist_t *it;

/* if not domain registered, return NULL directly */
if (root==NULL)
return NULL;

/* if no input provide, return the first domain */
if (_d==NULL)
return root->d;

Expand Down

0 comments on commit 8f0c677

Please sign in to comment.