Procházet zdrojové kódy

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
Daniel-Constantin Mierla před 13 roky
rodič
revize
997195274d

+ 6 - 2
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;

+ 4 - 2
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 | \

+ 43 - 0
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;
+}
+
+

+ 3 - 0
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 */