From 1d6d2e4b5b91990199b8351b473b8d159e362fba Mon Sep 17 00:00:00 2001 From: Liviu Chircu Date: Wed, 17 Jan 2024 12:18:06 +0200 Subject: [PATCH] for-each statement: Fix iteration when context is used Make sure to interpret the variable's context, if any, e.g.: for ($var(ct) in $(ct[*])) xlog("300 Redirect Contact: $var(ct)\n"); --- action.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/action.c b/action.c index 819df94adc9..4a82aea1857 100644 --- a/action.c +++ b/action.c @@ -1167,6 +1167,7 @@ int do_action(struct action* a, struct sip_msg* msg) static int for_each_handler(struct sip_msg *msg, struct action *a) { + struct sip_msg *msg_src = msg; pv_spec_p iter, spec; pv_param_t pvp; pv_value_t val; @@ -1189,6 +1190,13 @@ static int for_each_handler(struct sip_msg *msg, struct action *a) memset(&pvp, 0, sizeof pvp); pvp.pvi.type = PV_IDX_INT; pvp.pvn = spec->pvp.pvn; + if (spec->pvc && spec->pvc->contextf) { + msg_src = spec->pvc->contextf(msg); + if (!msg_src || msg_src == FAKED_REPLY) { + LM_BUG("Invalid pv context message: %p\n", msg_src); + return E_BUG; + } + } /* * for $json iterators, better to assume script writer @@ -1199,7 +1207,7 @@ static int for_each_handler(struct sip_msg *msg, struct action *a) op = COLONEQ_T; for (;;) { - if (spec->getf(msg, &pvp, &val) != 0) { + if (spec->getf(msg_src, &pvp, &val) != 0) { LM_ERR("failed to get spec value\n"); return E_BUG; }