Module: kamailio Branch: master Commit: e548172654b17140489f7432c34411b39c74471d URL: https://github.com/kamailio/kamailio/commit/e548172654b17140489f7432c34411b3...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2018-09-13T09:41:26+02:00
sanity: check for top Via header
- existing ones for Via are disabled/useless
---
Modified: src/modules/sanity/sanity.c Modified: src/modules/sanity/sanity.h Modified: src/modules/sanity/sanity_mod.c Modified: src/modules/sanity/sanity_mod.h
---
Diff: https://github.com/kamailio/kamailio/commit/e548172654b17140489f7432c34411b3... Patch: https://github.com/kamailio/kamailio/commit/e548172654b17140489f7432c34411b3...
---
diff --git a/src/modules/sanity/sanity.c b/src/modules/sanity/sanity.c index af90893e58..67ed61ef29 100644 --- a/src/modules/sanity/sanity.c +++ b/src/modules/sanity/sanity.c @@ -249,6 +249,25 @@ int check_required_headers(sip_msg_t* msg) { return SANITY_CHECK_PASSED; }
+/* check if the SIP version in the Via header is 2.0 */ +int check_via1_header(sip_msg_t* msg) +{ + LM_DBG("check via1 header\n"); + if (parse_headers(msg, HDR_VIA1_F, 0) != 0) { + LM_WARN("failed to parse the Via1 header\n"); + msg->msg_flags |= FL_MSG_NOREPLY; + return SANITY_CHECK_FAILED; + } + + if (msg->via1->host.s==NULL || msg->via1->host.len<0) { + LM_WARN("failed to parse the Via1 host\n"); + msg->msg_flags |= FL_MSG_NOREPLY; + return SANITY_CHECK_FAILED; + } + + return SANITY_CHECK_PASSED; +} + /* check if the SIP version in the Via header is 2.0 */ int check_via_sip_version(sip_msg_t* msg) {
diff --git a/src/modules/sanity/sanity.h b/src/modules/sanity/sanity.h index 2bf50c71f9..735425b7e6 100644 --- a/src/modules/sanity/sanity.h +++ b/src/modules/sanity/sanity.h @@ -36,6 +36,9 @@ int str2valid_uint(str* _number, unsigned int* _result); /* parses the given comma seperated string into a string list */ strl* parse_str_list(str* _string);
+/* check top Via header */ +int check_via1_header(sip_msg_t* msg); + /* compare the protocol string in the Via header with the transport */ int check_via_protocol(struct sip_msg* _msg);
diff --git a/src/modules/sanity/sanity_mod.c b/src/modules/sanity/sanity_mod.c index 6d8de764bc..c9c88678fb 100644 --- a/src/modules/sanity/sanity_mod.c +++ b/src/modules/sanity/sanity_mod.c @@ -141,6 +141,10 @@ int sanity_check(struct sip_msg* _msg, int msg_checks, int uri_checks) (ret = check_required_headers(_msg)) != SANITY_CHECK_PASSED) { goto done; } + if (SANITY_VIA1_HEADER & msg_checks && + (ret = check_via1_header(_msg)) != SANITY_CHECK_PASSED) { + goto done; + } if (SANITY_VIA_SIP_VERSION & msg_checks && (ret = check_via_sip_version(_msg)) != SANITY_CHECK_PASSED) { goto done; diff --git a/src/modules/sanity/sanity_mod.h b/src/modules/sanity/sanity_mod.h index e0e30eed28..3a7f89a05e 100644 --- a/src/modules/sanity/sanity_mod.h +++ b/src/modules/sanity/sanity_mod.h @@ -42,7 +42,8 @@ #define SANITY_CHECK_DIGEST (1<<11) #define SANITY_CHECK_DUPTAGS (1<<12) #define SANITY_CHECK_AUTHORIZATION (1<<13) -#define SANITY_MAX_CHECKS (1<<14) /* Make sure this is the highest value */ +#define SANITY_VIA1_HEADER (1<<14) +#define SANITY_MAX_CHECKS (1<<15) /* Make sure this is the highest value */
/* VIA_SIP_VERSION and VIA_PROTOCOL do not work yet * and PARSE_URIS is very expensive */