Skip to content

Commit

Permalink
transformations: Fix edge-cases with {param.value} and {uri.param}
Browse files Browse the repository at this point in the history
For inputs containing only the parameter part, these transformations
would return a bogus {NULL, 0} value (flagged as PV_VAL_STR), which
cannot be used in assignments or conditional checks:

Credits to Bogdan-Andrei Iancu for finding this issue!
  • Loading branch information
liviuchircu committed Jan 9, 2024
1 parent 0fb0094 commit b7c4f2a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions str.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ typedef struct __str_const str_const;
/* str initialization */
#define STR_NULL ((str){NULL, 0})
#define STR_NULL_const ((str_const){NULL, 0})
#define STR_EMPTY ((str){"", 0})
#define STR_EMPTY_const ((str_const){"", 0})
#define str_init(_string) ((str){_string, sizeof(_string) - 1})
#define str_const_init(_string) ((str_const){_string, sizeof(_string) - 1})

Expand Down
10 changes: 8 additions & 2 deletions transformations.c
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,10 @@ int tr_eval_uri(struct sip_msg *msg, tr_param_t *tp, int subtype,
if (pit->name.len==sv.len
&& strncasecmp(pit->name.s, sv.s, sv.len)==0)
{
val->rs = pit->body;
if (ZSTR(pit->body))
val->rs = STR_EMPTY;
else
val->rs = pit->body;
goto done;
}
}
Expand Down Expand Up @@ -2226,7 +2229,10 @@ int tr_eval_paramlist(struct sip_msg *msg, tr_param_t *tp, int subtype,
if (pit->name.len==sv.len
&& strncasecmp(pit->name.s, sv.s, sv.len)==0)
{
val->rs = pit->body;
if (ZSTR(pit->body))
val->rs = STR_EMPTY;
else
val->rs = pit->body;
goto done;
}
}
Expand Down

0 comments on commit b7c4f2a

Please sign in to comment.