Skip to content

Commit

Permalink
route params: Fix regression in 8761ce6
Browse files Browse the repository at this point in the history
The patch assumed that variables with PV_VAL_INT|PV_TYPE_INT have
symmetric values (e.g. 5 and "5"), whereas this is not always the case
(e.g. 1 and "INVITE", returned by $rm) and would proceed to duplicate
the output buffer as a int2str() buffer, for safety purposes.

The fix is to avoid the duplication completely (i.e. do not overwrite
"INVITE" with "1"), thanks to the route params array string buffers
having a sufficiently large lifetime in order to be safely returned to
the calling code asking for the route parameter.

(cherry picked from commit 6b9e140)
  • Loading branch information
liviuchircu committed Feb 16, 2023
1 parent 2ac8b16 commit cf79339
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions action.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ static pv_value_t *route_params_expand(struct sip_msg *msg,
case SCRIPTVAR_ST:
if(pv_get_spec_value(msg, (pv_spec_p)actions[index].u.data, res)==0)
{
if (res->flags & PV_VAL_STR) {
if (pvv_is_str(res)) {
/* but we need to duplicate the string */
if (pkg_str_dup(&tmp, &res->rs) == 0) {
res->rs.s = tmp.s;
Expand Down Expand Up @@ -578,8 +578,6 @@ static int route_param_get(struct sip_msg *msg, pv_param_t *ip,
index--;
*res = params[index];
res->flags &= ~PV_VAL_PKG; /* not interested in this flag */
if (res->flags & PV_VAL_INT)
res->rs.s = int2str(res->ri, &res->rs.len);

return 0;
}
Expand Down

0 comments on commit cf79339

Please sign in to comment.