drouting: handle errors in fixup function
authorDaniel-Constantin Mierla <miconda@gmail.com>
Thu, 27 Jul 2017 09:30:22 +0000 (11:30 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Thu, 27 Jul 2017 09:30:22 +0000 (11:30 +0200)
src/modules/drouting/drouting.c
src/modules/drouting/prefix_tree.c

index e18ce7f..d642716 100644 (file)
@@ -979,6 +979,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)
                {
@@ -987,33 +992,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');
index 7eddab6..cfb2cb1 100644 (file)
@@ -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++);
@@ -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;
 }
 
 
@@ -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 */
@@ -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) {