From d46701970e557508ac4bff8e0a6000cbf28b23cd Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Mon, 4 Mar 2019 20:09:41 +0100 Subject: [PATCH] TT#54406 pv_headers: pv_set_header() fix pv_parse_format * pv_value_t format is now parsed only if the type is PV_VAL_STR * pv_elem_free() is now called only if pv_value_t string was parsed, otherwise it causes operation on an invalid pointer Change-Id: Ic9d58fd5019732f24519d9d59da09c14a426afe6 --- .../sipwise/add_pv_headers_module.patch | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/debian/patches/sipwise/add_pv_headers_module.patch b/debian/patches/sipwise/add_pv_headers_module.patch index a6c0f246f..088c4a3a3 100644 --- a/debian/patches/sipwise/add_pv_headers_module.patch +++ b/debian/patches/sipwise/add_pv_headers_module.patch @@ -485,7 +485,7 @@ + --- /dev/null +++ b/src/modules/pv_headers/pv_headers.c -@@ -0,0 +1,1584 @@ +@@ -0,0 +1,1587 @@ +/* + * pv_headers + * @@ -1713,21 +1713,12 @@ + int idx = 0; + int cnt = 0; + int itype; ++ int pv_format_parsed = 0; + + hname = param->pvn.u.isname.name.s; + idx = param->pvi.u.ival; + itype = param->pvi.type; + -+ if (pv_parse_format(&val->rs, &p) < 0) { -+ LM_ERR("cannot parse format: %.*s\n", val->rs.len, val->rs.s); -+ goto err; -+ } -+ -+ if (pv_printf_s(msg, p, &fval) < 0) { -+ LM_ERR("cannot parse format: %.*s\n", val->rs.len, val->rs.s); -+ goto err; -+ } -+ + if ((xavp = xavp_get_child(&xavp_name, &hname)) == NULL) + idx = 0; + else if (idx < 0) @@ -1744,6 +1735,17 @@ + goto err; + } + } else if (val->flags & PV_VAL_STR) { ++ if (pv_parse_format(&val->rs, &p) < 0) { ++ LM_ERR("cannot parse format: %.*s\n", val->rs.len, val->rs.s); ++ goto err; ++ } ++ pv_format_parsed = 1; ++ ++ if (pv_printf_s(msg, p, &fval) < 0) { ++ LM_ERR("cannot use pv string: %.*s\n", val->rs.len, val->rs.s); ++ goto err; ++ } ++ + if (strchr(hname.s, ']') == NULL) { + if (pv_set_xavp(&xavp_name, &hname, &fval, SR_XTYPE_STR, 0, 1) < 0) + goto err; @@ -1760,16 +1762,17 @@ + if (pv_set_xavp(&xavp_name, &hname, &fval, SR_XTYPE_STR, idx, 0) < 0) + goto err; + } ++ if (pv_format_parsed) ++ pv_elem_free_all(p); + } else { + LM_ERR("header %.*s value can be either string or null\n", hname.len, hname.s); + goto err; + } -+ -+ pv_elem_free_all(p); + return 1; + +err: -+ pv_elem_free_all(p); ++ if (pv_format_parsed) ++ pv_elem_free_all(p); + return -1; +} +