Skip to content

Commit 2f3ee99

Browse files
Fix crash when calling script functions with omitted optional params
The crash would happen if the script function is exported with the CMD_PARAM_FIX_NULL flag and does not actually change the parameter value. Currently, only forward() uses the flag in this manner and is the only function affected by this crash. (cherry picked from commit 278c164)
1 parent b82b85b commit 2f3ee99

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

mod_fix.c

+9-10
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,20 @@ int fix_cmd(struct cmd_param *params, action_elem_t *elems)
162162
gp = NULL;
163163
if (param->flags & CMD_PARAM_OPT) {
164164
if (param->fixup && (param->flags & CMD_PARAM_FIX_NULL)) {
165-
if ((gp = alloc_gp()) == NULL)
166-
return E_OUT_OF_MEM;
167-
168-
gp->pval = NULL;
169-
gp->type = GPARAM_TYPE_VAL;
170-
171-
h = gp->pval;
172-
if (param->fixup(&gp->pval) < 0) {
165+
h = NULL;
166+
if (param->fixup(&h) < 0) {
173167
LM_ERR("Fixup failed for param [%d]\n", i);
174168
ret = E_UNSPEC;
175169
goto error;
176170
}
177-
if (h!=gp->pval)
178-
gp->type = GPARAM_TYPE_FIXUP;
179171

172+
if (h != NULL) {
173+
if ((gp = alloc_gp()) == NULL)
174+
return E_OUT_OF_MEM;
175+
176+
gp->type = GPARAM_TYPE_FIXUP;
177+
gp->pval = h;
178+
}
180179
}
181180

182181
goto fill_elems;

0 commit comments

Comments
 (0)