Module: kamailio Branch: 5.2 Commit: c2fd0db7f9a207a0eecf08e8ebafe0ecdc90d764 URL: https://github.com/kamailio/kamailio/commit/c2fd0db7f9a207a0eecf08e8ebafe0ec...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2020-10-12T10:49:57+02:00
tm: do not add duplicate headers in local requests
(cherry picked from commit ada3701d22b1fd579f06b4f54fa695fa988e685f) (cherry picked from commit f57c900b438f3233fa1e9a9d3ca8cd383a30baa6) (cherry picked from commit 31ac72f9b43862f9005a0f691a52c8439fe1e8c5)
---
Modified: src/modules/tm/t_msgbuilder.c
---
Diff: https://github.com/kamailio/kamailio/commit/c2fd0db7f9a207a0eecf08e8ebafe0ec... Patch: https://github.com/kamailio/kamailio/commit/c2fd0db7f9a207a0eecf08e8ebafe0ec...
---
diff --git a/src/modules/tm/t_msgbuilder.c b/src/modules/tm/t_msgbuilder.c index 87c27eed05..3f282a93c5 100644 --- a/src/modules/tm/t_msgbuilder.c +++ b/src/modules/tm/t_msgbuilder.c @@ -281,6 +281,7 @@ char *build_local_reparse(tm_cell_t *Trans,unsigned int branch, #endif /* CANCEL_REASON_SUPPORT */ int hadded = 0; sr_cfgenv_t *cenv = NULL; + hdr_flags_t hdr_flags = 0;
invite_buf = Trans->uac[branch].request.buffer; invite_len = Trans->uac[branch].request.buffer_len; @@ -379,6 +380,11 @@ char *build_local_reparse(tm_cell_t *Trans,unsigned int branch, switch(hf_type) { case HDR_CSEQ_T: /* find the method name and replace it */ + if(hdr_flags & HDR_CSEQ_F) { + LM_DBG("duplicate CSeq header\n"); + goto errorhdr; + } + hdr_flags |= HDR_CSEQ_F; while ((s < invite_buf_end) && ((*s == ':') || (*s == ' ') || (*s == '\t') || ((*s >= '0') && (*s <= '9'))) @@ -399,6 +405,12 @@ char *build_local_reparse(tm_cell_t *Trans,unsigned int branch, break;
case HDR_TO_T: + if(hdr_flags & HDR_TO_F) { + LM_DBG("duplicate To header\n"); + goto errorhdr; + } + hdr_flags |= HDR_TO_F; + if (to_len == 0) { /* there is no To tag required, just copy paste * the header */ @@ -413,7 +425,25 @@ char *build_local_reparse(tm_cell_t *Trans,unsigned int branch, break;
case HDR_FROM_T: + /* copy hf */ + if(hdr_flags & HDR_FROM_F) { + LM_DBG("duplicate From header\n"); + goto errorhdr; + } + hdr_flags |= HDR_FROM_F; + s = lw_next_line(s, invite_buf_end); + append_str(d, s1, s - s1); + break; case HDR_CALLID_T: + /* copy hf */ + if(hdr_flags & HDR_CALLID_F) { + LM_DBG("duplicate Call-Id header\n"); + goto errorhdr; + } + hdr_flags |= HDR_CALLID_F; + s = lw_next_line(s, invite_buf_end); + append_str(d, s1, s - s1); + break; case HDR_ROUTE_T: case HDR_MAXFORWARDS_T: /* copy hf */ @@ -515,6 +545,7 @@ char *build_local_reparse(tm_cell_t *Trans,unsigned int branch, /* HDR_EOH_T was not found in the buffer, the message is corrupt */ LM_ERR("HDR_EOH_T was not found\n");
+errorhdr: shm_free(cancel_buf); error: LM_ERR("cannot build %.*s request\n", method_len, method);