Skip to content

Commit

Permalink
mtree: access values before safety checks of variables
Browse files Browse the repository at this point in the history
(cherry picked from commit 56d1d31)
  • Loading branch information
miconda committed Aug 30, 2017
1 parent 2232c34 commit 954fd81
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/modules/mtree/mtree.c
Expand Up @@ -985,12 +985,13 @@ int mt_rpc_add_tvalues(rpc_t* rpc, void* ctx, m_tree_t *pt, str *tomatch)
mt_node_t *itn;
mt_is_t *tvalues;
void *vstruct = NULL;
str prefix = *tomatch;
str prefix = STR_NULL;

if (pt == NULL || tomatch == NULL || tomatch->s == NULL) {
LM_ERR("bad parameters\n");
return -1;
}
prefix = *tomatch;

l = 0;
itn = pt->head;
Expand Down Expand Up @@ -1051,7 +1052,7 @@ int mt_rpc_match_prefix(rpc_t* rpc, void* ctx, m_tree_t *it,
is_t *tvalue;
mt_dw_t *dw;
int tprefix_len = 0;
str prefix = *tomatch;
str prefix = STR_NULL;
void *vstruct = NULL;

#define MT_MAX_DST_LIST 64
Expand All @@ -1063,6 +1064,7 @@ int mt_rpc_match_prefix(rpc_t* rpc, void* ctx, m_tree_t *it,
LM_ERR("bad parameters\n");
return -1;
}
prefix = *tomatch;

if (rpc->add(ctx, "S", &it->tname) < 0) {
rpc->fault(ctx, 500, "Internal error adding tname");
Expand Down
16 changes: 10 additions & 6 deletions src/modules/mtree/mtree_mod.c
Expand Up @@ -761,16 +761,20 @@ static int mt_load_db_trees()
{
/* check for NULL values ?!?! */
tname.s = (char*)(RES_ROWS(db_res)[i].values[0].val.string_val);
tname.len = strlen(tname.s);

tprefix.s = (char*)(RES_ROWS(db_res)[i].values[1].val.string_val);
tprefix.len = strlen(tprefix.s);

tvalue.s = (char*)(RES_ROWS(db_res)[i].values[2].val.string_val);

if(tprefix.s==NULL || tvalue.s==NULL || tname.s==NULL)
{
LM_ERR("Error - null fields in db\n");
continue;
}

tname.len = strlen(tname.s);
tprefix.len = strlen(tprefix.s);
tvalue.len = strlen(tvalue.s);

if(tprefix.s==NULL || tvalue.s==NULL || tname.s==NULL ||
tprefix.len<=0 || tvalue.len<=0 || tname.len<=0)
if(tname.len<=0 || tprefix.len<=0 || tvalue.len<=0)
{
LM_ERR("Error - bad values in db\n");
continue;
Expand Down

0 comments on commit 954fd81

Please sign in to comment.