From a902a2503194fee857003dd9bccb4e165e31d333 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Wed, 25 May 2022 11:09:28 +0200 Subject: [PATCH] TT#165301 dialog: dlg_get_var assure return null on error Change-Id: I6f86144b6464b29341f4b199242340ff65b6a0a9 --- debian/patches/series | 1 + .../sipwise/dialog-rework-dlg_get_var.patch | 86 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 debian/patches/sipwise/dialog-rework-dlg_get_var.patch diff --git a/debian/patches/series b/debian/patches/series index 8aeb03c20..2541b96dc 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -76,6 +76,7 @@ sipwise/pv_headers-use-memset.patch sipwise/lcr-stopper_mode-parameter.patch sipwise/dialog-dlg_get_var.patch sipwise/dialog-dlg_set_var.patch +sipwise/dialog-rework-dlg_get_var.patch # ### Don't just put stuff in any order ### use gbp pq import/export tooling to help maintain patches diff --git a/debian/patches/sipwise/dialog-rework-dlg_get_var.patch b/debian/patches/sipwise/dialog-rework-dlg_get_var.patch new file mode 100644 index 000000000..72eb4d9f3 --- /dev/null +++ b/debian/patches/sipwise/dialog-rework-dlg_get_var.patch @@ -0,0 +1,86 @@ +From: Victor Seva +Date: Wed, 25 May 2022 11:07:39 +0200 +Subject: dialog: rework dlg_get_var + +be sure to set null to dst_var on error +--- + src/modules/dialog/dialog.c | 29 +++++++++++++++++++---------- + 1 file changed, 19 insertions(+), 10 deletions(-) + +diff --git a/src/modules/dialog/dialog.c b/src/modules/dialog/dialog.c +index 42e3e1b..2b860c2 100644 +--- a/src/modules/dialog/dialog.c ++++ b/src/modules/dialog/dialog.c +@@ -1540,53 +1540,62 @@ static int w_dlg_get_var(struct sip_msg *msg, char *ci, char *ft, char *tt, char + str k = STR_NULL; + str *val = NULL; + pv_value_t dst_val; +- pv_spec_t* dst_pv; ++ pv_spec_t* dst_pv = (pv_spec_t *)pv; + + if(ci==0 || ft==0 || tt==0) + { + LM_ERR("invalid parameters\n"); +- return -1; ++ goto error; + } + + if(fixup_get_svalue(msg, (gparam_p)ci, &sc)!=0) + { + LM_ERR("unable to get Call-ID\n"); +- return -1; ++ goto error; + } + + if(fixup_get_svalue(msg, (gparam_p)ft, &sf)!=0) + { + LM_ERR("unable to get From tag\n"); +- return -1; ++ goto error; + } + + if(fixup_get_svalue(msg, (gparam_p)tt, &st)!=0) + { + LM_ERR("unable to get To Tag\n"); +- return -1; ++ goto error; + } + if(st.s==NULL || st.len == 0) + { + LM_ERR("invalid To tag parameter\n"); +- return -1; ++ goto error; + } + if(fixup_get_svalue(msg, (gparam_p)key, &k)!=0) + { + LM_ERR("unable to get key name\n"); +- return -1; ++ goto error; + } +- dst_pv = (pv_spec_t *)pv; + val = ki_dlg_get_var(msg, &sc, &sf, &st, &k); + if(val) { + memset(&dst_val, 0, sizeof(pv_value_t)); + dst_val.flags |= PV_VAL_STR; + dst_val.rs.s = val->s; + dst_val.rs.len = val->len; +- if(pv_set_spec_value(msg, dst_pv, 0, &dst_val) != 0) return -1; + } else { +- if(pv_get_null(msg, NULL, &dst_val) != 0) return -1; ++ pv_get_null(msg, NULL, &dst_val); ++ } ++ if(pv_set_spec_value(msg, dst_pv, 0, &dst_val) != 0) { ++ LM_ERR("unable to set value to dst_pv\n"); ++ if(val) goto error; else return -1; + } + return 1; ++ ++error: ++ pv_get_null(msg, NULL, &dst_val); ++ if(pv_set_spec_value(msg, dst_pv, 0, &dst_val) != 0) { ++ LM_ERR("unable to set null value to dst_pv\n"); ++ } ++ return -1; + } + + static int fixup_dlg_get_var(void** param, int param_no)