From 041a7b5bc79367297d4e7d340176b4b096a1c835 Mon Sep 17 00:00:00 2001 From: Liviu Chircu Date: Tue, 9 Jan 2024 15:15:05 +0200 Subject: [PATCH] transformations: Fix edge-cases with {param.value} and {uri.param} 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! (cherry picked from commit b7c4f2a3bb3307b3c505f7017934a52bef8762fd) --- str.h | 2 ++ transformations.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/str.h b/str.h index 3629778ea95..5229928f42c 100644 --- a/str.h +++ b/str.h @@ -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} diff --git a/transformations.c b/transformations.c index 7b37300ee09..3c7dad652e1 100644 --- a/transformations.c +++ b/transformations.c @@ -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; } } @@ -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; } }