From 69cd7f709356f439d4ca6bf301de4448a5cd93d3 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Wed, 10 Mar 2021 19:21:45 +0100 Subject: [PATCH] TT#114315 pv_headers: fix split detection marker If we set Diversion in split_headers and we get a header like > "RULTEST, normalaa" ;reason=unconditional There was false detection of two Diversion headers. Skip split marker between double quotes to avoid this Change-Id: Ib2189bc0029f244fd59f14df5b3d1df745271038 (cherry picked from commit a812be8e0fe518a23b6cdb56e28716939ca7c9b4) (cherry picked from commit f642443991b539b3782e113b417a35bbbbc93c6e) (cherry picked from commit 0d478695f49b33eff9faaa53754cd230cb0f767a) --- .../sipwise/add_pv_headers_module.patch | 68 ++++++++++++++----- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/debian/patches/sipwise/add_pv_headers_module.patch b/debian/patches/sipwise/add_pv_headers_module.patch index f8a1371b1..6496dc56b 100644 --- a/debian/patches/sipwise/add_pv_headers_module.patch +++ b/debian/patches/sipwise/add_pv_headers_module.patch @@ -6,9 +6,9 @@ Subject: add_pv_headers_module src/Makefile.groups | 2 +- src/modules/pv_headers/Makefile | 12 + src/modules/pv_headers/README | 488 ++++++++ - src/modules/pv_headers/pv_headers.c | 2134 +++++++++++++++++++++++++++++++++++ + src/modules/pv_headers/pv_headers.c | 2170 +++++++++++++++++++++++++++++++++++ src/modules/pv_headers/pv_headers.h | 30 + - 5 files changed, 2665 insertions(+), 1 deletion(-) + 5 files changed, 2701 insertions(+), 1 deletion(-) create mode 100644 src/modules/pv_headers/Makefile create mode 100644 src/modules/pv_headers/README create mode 100644 src/modules/pv_headers/pv_headers.c @@ -541,10 +541,10 @@ index 0000000..30bd1da + $var(test) = $x_rr; diff --git a/src/modules/pv_headers/pv_headers.c b/src/modules/pv_headers/pv_headers.c new file mode 100644 -index 0000000..30a2909 +index 0000000..7683293 --- /dev/null +++ b/src/modules/pv_headers/pv_headers.c -@@ -0,0 +1,2134 @@ +@@ -0,0 +1,2170 @@ +/* + * pv_headers + * @@ -663,7 +663,8 @@ index 0000000..30a2909 +static int pv_str_free(str *s); +static int pv_str_copy(str *dst, str *src, unsigned int max_size); +static int pv_extract_display_uri(char *suri, str *display, str *duri); -+static int pv_split_values(str *s, char d[][header_value_size], int *d_size, int keep_spaces); ++static char *pv_detect_split_char(char *s); ++static int pv_split_values(str *s, char d[][header_value_size], int *d_size, int keep_spaces, char *marker); + +static sr_xavp_t * pv_xavp_new_value(str *name, sr_xval_t *val); +static int pv_xavp_append_value(str *name, sr_xval_t *val, sr_xavp_t **start); @@ -847,6 +848,7 @@ index 0000000..30a2909 + int idx = 0, d_size = 0; + str val_part = STR_NULL; + int br_idx; ++ char *marker = NULL; + + pv_get_branch_index(msg, &br_idx); + LM_DBG("br_idx: %d\n", br_idx); @@ -885,10 +887,10 @@ index 0000000..30a2909 + } + pv_str_copy(&val, &hf->body, header_value_size); + -+ if (str_hash_get(&split_headers, name.s, name.len) && -+ strchr(val.s, ',') != NULL) { ++ if (( marker = pv_detect_split_char(val.s)) != NULL && ++ str_hash_get(&split_headers, name.s, name.len)) { + -+ if (pv_split_values(&val, hvals, &d_size, 1) < 0) { ++ if (pv_split_values(&val, hvals, &d_size, 1, marker) < 0) { + LM_ERR("could not parse Diversion header comma separated value"); + return -1; + } @@ -1607,9 +1609,38 @@ index 0000000..30a2909 + return 1; +} + -+int pv_split_values(str *s, char d[][header_value_size], int *d_size, int keep_spaces) ++char *pv_detect_split_char(char *val) +{ -+ char p; ++ char *quote_a = NULL, *quote_b = NULL; ++ char *split = NULL; ++ ++ if(val == NULL) ++ return NULL; ++ ++ split = strchr(val, ','); ++ if(split == NULL) { ++ LM_DBG("no split marker detected\n"); ++ return NULL; ++ } ++ ++ quote_a = strchr(val, '"'); ++ if(quote_a == NULL || split < quote_a) { ++ LM_DBG("split marker detected[%ld], not between quotes\n", split - val); ++ return split; ++ } ++ ++ quote_b = strchr(val + (split - quote_a + 1), '"'); ++ if(quote_b == NULL) { ++ LM_DBG("split marker detected[%ld], quote occurrence unbalanced[%ld]\n", ++ split - val, quote_b - val); ++ return split; ++ } ++ return pv_detect_split_char(val + (quote_b - val + 1)); ++} ++ ++int pv_split_values(str *s, char d[][header_value_size], int *d_size, int keep_spaces, char *marker) ++{ ++ char *p = NULL; + int idx = 0, c_idx = 0; + + *d_size = -1; @@ -1618,12 +1649,17 @@ index 0000000..30a2909 + *d_size = 0; + return 1; + } -+ ++ if(!marker) ++ marker = pv_detect_split_char(s->s); + while (idx < s->len) { -+ strncpy(&p, s->s+idx++,1); -+ if (keep_spaces == 0 && strncmp(&p, " ", 1) == 0) ++ strncpy(p, s->s+idx++,1); ++ if (keep_spaces == 0 && strncmp(p, " ", 1) == 0) + continue; -+ if (strncmp(&p, ",", 1) == 0) { ++ if (p == marker) { ++ if(marker && idx < s->len) { ++ LM_DBG("search next split marker[%d]\n", idx); ++ marker = pv_detect_split_char(p + 1); ++ } + if (c_idx == 0) + continue; + if (c_idx+1 < header_value_size) @@ -1634,7 +1670,7 @@ index 0000000..30a2909 + } + if (c_idx == 0) + (*d_size)++; -+ strncpy(&d[*d_size][c_idx++], &p, 1); ++ strncpy(&d[*d_size][c_idx++], p, 1); + } + + if (c_idx > 0) { @@ -1864,7 +1900,7 @@ index 0000000..30a2909 + int idx = 0, d_size = 0; + str val = STR_NULL; + -+ if (pv_split_values(keys, split, &d_size, 0) < 0) { ++ if (pv_split_values(keys, split, &d_size, 0, NULL) < 0) { + LM_ERR("could not parse %s param\n", desc); + return -1; + }