Module: sip-router
Branch: master
Commit: 997195274d2fc9d877fb2f3ff127e50773ebc4ab
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=9971952…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Tue Jan 10 23:07:36 2012 +0100
sanity: new checks for duplicates of tag params in To/From
- the values are used to identify SIP dialogs and must be unique
- reported in FS#177
---
modules/sanity/mod_sanity.c | 8 ++++++--
modules/sanity/mod_sanity.h | 6 ++++--
modules/sanity/sanity.c | 43 +++++++++++++++++++++++++++++++++++++++++++
modules/sanity/sanity.h | 3 +++
4 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/modules/sanity/mod_sanity.c b/modules/sanity/mod_sanity.c
index b54d2e3..fd50a79 100644
--- a/modules/sanity/mod_sanity.c
+++ b/modules/sanity/mod_sanity.c
@@ -145,8 +145,8 @@ static int sanity_fixup(void** param, int param_no) {
LOG(L_ERR, "sanity: failed to convert second integer argument\n");
return E_UNSPEC;
}
- if ((checks < 1) || (checks > (SANITY_DEFAULT_URI_CHECKS))) {
- LOG(L_ERR, "sanity: second input parameter (%i) outside of valid range
1-%i\n", checks, SANITY_DEFAULT_URI_CHECKS);
+ if ((checks < 1) || (checks >= (SANITY_URI_MAX_CHECKS))) {
+ LOG(L_ERR, "sanity: second input parameter (%i) outside of valid range
<1-%i\n", checks, SANITY_URI_MAX_CHECKS);
return E_UNSPEC;
}
*param = (void*)(long)checks;
@@ -215,6 +215,10 @@ int sanity_check(struct sip_msg* _msg, int msg_checks, int
uri_checks)
(ret = check_digest(_msg, uri_checks)) != SANITY_CHECK_PASSED) {
goto done;
}
+ if (SANITY_CHECK_DUPTAGS & msg_checks &&
+ (ret = check_duptags(_msg)) != SANITY_CHECK_PASSED) {
+ goto done;
+ }
done:
return ret;
diff --git a/modules/sanity/mod_sanity.h b/modules/sanity/mod_sanity.h
index 5586dce..8221329 100644
--- a/modules/sanity/mod_sanity.h
+++ b/modules/sanity/mod_sanity.h
@@ -47,7 +47,8 @@
#define SANITY_PROXY_REQUIRE (1<<9)
#define SANITY_PARSE_URIS (1<<10)
#define SANITY_CHECK_DIGEST (1<<11)
-#define SANITY_MAX_CHECKS (1<<12) /* Make sure this is the highest
value */
+#define SANITY_CHECK_DUPTAGS (1<<12)
+#define SANITY_MAX_CHECKS (1<<13) /* Make sure this is the highest
value */
/* VIA_SIP_VERSION and VIA_PROTOCOL do not work yet
* and PARSE_URIS is very expensive */
@@ -59,13 +60,14 @@
SANITY_CL | \
SANITY_EXPIRES_VALUE | \
SANITY_PROXY_REQUIRE | \
- SANITY_CHECK_DIGEST
+ SANITY_CHECK_DIGEST
#define SANITY_URI_CHECK_RURI (1<<0)
#define SANITY_URI_CHECK_FROM (1<<1)
#define SANITY_URI_CHECK_TO (1<<2)
#define SANITY_URI_CHECK_CONTACT (1<<3)
+#define SANITY_URI_MAX_CHECKS (1<<4) /* Make sure this is the highest value */
#define SANITY_DEFAULT_URI_CHECKS SANITY_URI_CHECK_RURI | \
SANITY_URI_CHECK_FROM | \
diff --git a/modules/sanity/sanity.c b/modules/sanity/sanity.c
index 9466313..2331289 100644
--- a/modules/sanity/sanity.c
+++ b/modules/sanity/sanity.c
@@ -40,6 +40,7 @@
#include "../../parser/digest/digest.h"
#include "../../parser/contact/parse_contact.h"
#include "../../parser/parse_to.h"
+#include "../../parser/parse_from.h"
#define UNSUPPORTED_HEADER "Unsupported: "
#define UNSUPPORTED_HEADER_LEN (sizeof(UNSUPPORTED_HEADER)-1)
@@ -994,3 +995,45 @@ int check_digest(struct sip_msg* msg, int checks)
return SANITY_CHECK_PASSED;
}
+
+
+/* check for the presence of duplicate tag prameters in To/From headers */
+int check_duptags(sip_msg_t* _msg)
+{
+ to_body_t *tb;
+ to_param_t *tp;
+ int n;
+
+ if(parse_from_header(_msg)<0 || parse_to_header(_msg)<0) {
+ DBG("check_duptags failed while parsing\n");
+ return SANITY_CHECK_FAILED;
+ }
+ tb = get_from(_msg);
+ if(tb->tag_value.s!=NULL) {
+ n = 0;
+ for(tp = tb->param_lst; tp; tp = tp->next) {
+ if(tp->type==TAG_PARAM)
+ n++;
+ }
+ if(n>1) {
+ DBG("check_duptags failed for From header\n");
+ return SANITY_CHECK_FAILED;
+ }
+ }
+ tb = get_to(_msg);
+ if(tb->tag_value.s!=NULL) {
+ n = 0;
+ for(tp = tb->param_lst; tp; tp = tp->next) {
+ if(tp->type==TAG_PARAM)
+ n++;
+ }
+ if(n>1) {
+ DBG("check_duptags failed for To header\n");
+ return SANITY_CHECK_FAILED;
+ }
+ }
+
+ return SANITY_CHECK_PASSED;
+}
+
+
diff --git a/modules/sanity/sanity.h b/modules/sanity/sanity.h
index 7109b6e..e910ed1 100644
--- a/modules/sanity/sanity.h
+++ b/modules/sanity/sanity.h
@@ -81,4 +81,7 @@ int check_parse_uris(struct sip_msg* _msg, int checks);
*/
int check_digest(struct sip_msg* _msg, int checks);
+/* check if there are duplicate tag params in From/To headers */
+int check_duptags(sip_msg_t* _msg);
+
#endif /* SANITY_CHK_H */