Skip to content

Commit

Permalink
Fix preservation for the values of func params.
Browse files Browse the repository at this point in the history
Some function may change the params (holders) during runtime, so it is better to provide a safety mechanism here. Simply copy the str/int into a temporaty holder for each function execution
  • Loading branch information
bogdan-iancu committed Apr 16, 2019
1 parent 4c43cc8 commit ea62ec2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
38 changes: 30 additions & 8 deletions mod_fix.c
Expand Up @@ -87,6 +87,7 @@ int fix_cmd(struct cmd_param *params, action_elem_t *elems)
int ret;
pv_elem_t *pve;
regex_t *re = NULL;
void *h;

for (param=params, i=1; param->flags; param++, i++) {
if ((elems[i].type == NOSUBTYPE) ||
Expand All @@ -100,11 +101,14 @@ int fix_cmd(struct cmd_param *params, action_elem_t *elems)
gp->pval = NULL;
gp->type = GPARAM_TYPE_VAL;

h = gp->pval;
if (param->fixup(&gp->pval) < 0) {
LM_ERR("Fixup failed for param [%d]\n", i);
ret = E_UNSPEC;
goto error;
}
if (h!=gp->pval)
gp->type = GPARAM_TYPE_FIXUP;

}

Expand All @@ -126,10 +130,15 @@ int fix_cmd(struct cmd_param *params, action_elem_t *elems)
gp->pval = &gp->v.ival;
gp->type = GPARAM_TYPE_VAL;

if (param->fixup && param->fixup(&gp->pval) < 0) {
LM_ERR("Fixup failed for param [%d]\n", i);
ret = E_UNSPEC;
goto error;
if (param->fixup) {
h = gp->pval;
if (param->fixup(&gp->pval) < 0) {
LM_ERR("Fixup failed for param [%d]\n", i);
ret = E_UNSPEC;
goto error;
}
if (h!=gp->pval)
gp->type = GPARAM_TYPE_FIXUP;
}
} else if (elems[i].type == SCRIPTVAR_ST) {
gp->pval = elems[i].u.data;
Expand Down Expand Up @@ -159,10 +168,15 @@ int fix_cmd(struct cmd_param *params, action_elem_t *elems)
gp->pval = &gp->v.sval;
gp->type = GPARAM_TYPE_VAL;

if (param->fixup && param->fixup(&gp->pval) < 0) {
LM_ERR("Fixup failed for param [%d]\n", i);
ret = E_UNSPEC;
goto error;
if (param->fixup) {
h = gp->pval;
if (param->fixup(&gp->pval) < 0) {
LM_ERR("Fixup failed for param [%d]\n", i);
ret = E_UNSPEC;
goto error;
}
if (h!=gp->pval)
gp->type = GPARAM_TYPE_FIXUP;
}
} else {
if (param->flags & CMD_PARAM_STATIC) {
Expand Down Expand Up @@ -282,6 +296,10 @@ int get_cmd_fixups(struct sip_msg* msg, struct cmd_param *params,

switch (gp->type) {
case GPARAM_TYPE_VAL:
tmp_vals[i].ri = *(int*)gp->pval;
cmdp[i-1] = &tmp_vals[i].ri;
break;
case GPARAM_TYPE_FIXUP:
cmdp[i-1] = gp->pval;
break;
case GPARAM_TYPE_PVS:
Expand Down Expand Up @@ -314,6 +332,10 @@ int get_cmd_fixups(struct sip_msg* msg, struct cmd_param *params,

switch (gp->type) {
case GPARAM_TYPE_VAL:
tmp_vals[i].rs = *(str*)gp->pval;
cmdp[i-1] = &tmp_vals[i].rs;
break;
case GPARAM_TYPE_FIXUP:
cmdp[i-1] = gp->pval;
break;
case GPARAM_TYPE_PVE:
Expand Down
1 change: 1 addition & 0 deletions mod_fix.h
Expand Up @@ -29,6 +29,7 @@
#define GPARAM_TYPE_VAL 0
#define GPARAM_TYPE_PVS 1
#define GPARAM_TYPE_PVE 2
#define GPARAM_TYPE_FIXUP 3

typedef struct _gparam
{
Expand Down

0 comments on commit ea62ec2

Please sign in to comment.