Skip to content

Commit

Permalink
drouting: handle errors in fixup function
Browse files Browse the repository at this point in the history
(cherry picked from commit 3620250)
  • Loading branch information
miconda committed Aug 30, 2017
1 parent 20a61ab commit e7e1fe4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
23 changes: 13 additions & 10 deletions src/modules/drouting/drouting.c
Expand Up @@ -926,6 +926,11 @@ static int fixup_do_routing(void** param, int param_no)

if (param_no==1)
{
if ( s==NULL || s[0]==0 ) {
LM_CRIT("empty group id definition");
return E_CFG;
}

drg = (dr_group_t*)pkg_malloc(sizeof(dr_group_t));
if(drg==NULL)
{
Expand All @@ -934,33 +939,31 @@ static int fixup_do_routing(void** param, int param_no)
}
memset(drg, 0, sizeof(dr_group_t));

if ( s==NULL || s[0]==0 ) {
LM_CRIT("empty group id definition");
return E_CFG;
}

if (s[0]=='$') {
/* param is a PV (AVP only supported) */
r.s = s;
r.len = strlen(s);
if (pv_parse_spec( &r, &avp_spec)==0
|| avp_spec.type!=PVT_AVP) {
|| avp_spec.type!=PVT_AVP) {
LM_ERR("malformed or non AVP %s AVP definition\n", s);
pkg_free(drg);
return E_CFG;
}

if( pv_get_avp_name(0, &(avp_spec.pvp), &(drg->u.avp_id.name),
&(drg->u.avp_id.type) )!=0) {
&(drg->u.avp_id.type) )!=0) {
LM_ERR("[%s]- invalid AVP definition\n", s);
pkg_free(drg);
return E_CFG;
}
drg->type = 1;
/* do not free the param as the AVP spec may point inside
this string*/
/* do not free the param as the AVP spec may point inside
* this string*/
} else {
while(s && *s) {
if(*s<'0' || *s>'9') {
LM_ERR( "bad number\n");
LM_ERR("bad number\n");
pkg_free(drg);
return E_UNSPEC;
}
drg->u.grp_id = (drg->u.grp_id)*10+(*s-'0');
Expand Down
17 changes: 5 additions & 12 deletions src/modules/drouting/prefix_tree.c
Expand Up @@ -78,7 +78,8 @@ internal_check_rt(
rt_info_wrp_t* rtlw=NULL;

if((NULL==ptn) || (NULL==ptn->rg))
goto err_exit;
return NULL;

rg_pos = ptn->rg_pos;
rg=ptn->rg;
for(i=0;(i<rg_pos) && (rg[i].rgid!=rgid);i++);
Expand All @@ -88,15 +89,12 @@ internal_check_rt(
rtlw=rg[i].rtlw;
while(rtlw!=NULL) {
if(check_time(rtlw->rtl->time_rec))
goto ok_exit;
return rtlw->rtl;
rtlw=rtlw->next;
}
}
err_exit:
return NULL;

ok_exit:
return rtlw?rtlw->rtl:0;
return NULL;
}


Expand Down Expand Up @@ -129,8 +127,6 @@ get_prefix(
/* go the tree down to the last digit in the
* prefix string or down to a leaf */
while(tmp< (prefix->s+prefix->len)) {
if(NULL == tmp)
goto err_exit;
idx = get_node_index(*tmp);
if (idx == -1){
/* unknown character in the prefix string */
Expand All @@ -147,11 +143,8 @@ get_prefix(
ptree = ptree->ptnode[idx].next;
tmp++;
}
/* go in the tree up to the root trying to match the
* prefix */
/* go in the tree up to the root trying to match the prefix */
while(ptree !=NULL ) {
if(NULL == tmp)
goto err_exit;
/* is it a real node or an intermediate one */
idx = get_node_index(*tmp);
if(idx!=-1 && NULL != ptree->ptnode[idx].rg) {
Expand Down

0 comments on commit e7e1fe4

Please sign in to comment.