Module: kamailio
Branch: 5.3
Commit: 5d5dd676d299a27f14c6079b497cf1ae311909ce
URL:
https://github.com/kamailio/kamailio/commit/5d5dd676d299a27f14c6079b497cf1a…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2020-10-12T10:29:57+02:00
sanity: extended check 4 (required headers) for uniqueness
- Call-ID, CSeq, From and To have to be only once
(cherry picked from commit a9ede56b35990fcc9164af0775f503e49e33377e)
(cherry picked from commit 7adf410af754f1bb737edca6f427ef02d3441cda)
---
Modified: src/modules/sanity/sanity.c
---
Diff:
https://github.com/kamailio/kamailio/commit/5d5dd676d299a27f14c6079b497cf1a…
Patch:
https://github.com/kamailio/kamailio/commit/5d5dd676d299a27f14c6079b497cf1a…
---
diff --git a/src/modules/sanity/sanity.c b/src/modules/sanity/sanity.c
index 04ad2b86d6..842d394194 100644
--- a/src/modules/sanity/sanity.c
+++ b/src/modules/sanity/sanity.c
@@ -299,8 +299,21 @@ int check_ruri_scheme(sip_msg_t* msg) {
return SANITY_CHECK_PASSED;
}
+#define SANITY_HDR_DUPCHECK(_hf, _hdr_flags, _hdr_type, _hdr_flag, _hdr_name) \
+ do { \
+ if((_hf)->type == _hdr_type) { \
+ if(_hdr_flags & _hdr_flag) { \
+ LM_DBG("duplicated %s header\n", _hdr_name); \
+ return SANITY_CHECK_FAILED; \
+ } \
+ _hdr_flags |= _hdr_flag; \
+ } \
+ } while(0)
+
/* check for the presence of the minimal required headers */
int check_required_headers(sip_msg_t* msg) {
+ hdr_field_t* hf;
+ hdr_flags_t hdr_flags = 0;
LM_DBG("check_required_headers entered\n");
@@ -309,6 +322,20 @@ int check_required_headers(sip_msg_t* msg) {
LM_DBG("check_required_headers failed\n");
return SANITY_CHECK_FAILED;
}
+ if (parse_headers(msg, HDR_EOH_F, 0) != 0) {
+ LM_ERR("failed to parse headers\n");
+ if (sanity_reply(msg, 400, "Bad Headers") < 0) {
+ LM_WARN("failed to send 400 reply\n");
+ }
+ return SANITY_CHECK_FAILED;
+ }
+ for (hf=msg->headers; hf; hf=hf->next) {
+ SANITY_HDR_DUPCHECK(hf, hdr_flags, HDR_FROM_T, HDR_FROM_F, "From");
+ SANITY_HDR_DUPCHECK(hf, hdr_flags, HDR_TO_T, HDR_TO_F, "To");
+ SANITY_HDR_DUPCHECK(hf, hdr_flags, HDR_CALLID_T, HDR_CALLID_F, "Call-Id");
+ SANITY_HDR_DUPCHECK(hf, hdr_flags, HDR_CSEQ_T, HDR_CSEQ_F, "CSeq");
+ }
+
/* TODO: check for other required headers according to request type */
LM_DBG("check_required_headers passed\n");