Browse Source

core: parser/contact - basic validation tests for contact uri

(cherry picked from commit fc52a54370c085d6fa951da876eee99580677922)
Daniel-Constantin Mierla 1 year ago
parent
commit
d75dba6118
1 changed files with 21 additions and 0 deletions
  1. 21 0
      src/core/parser/contact/contact.c

+ 21 - 0
src/core/parser/contact/contact.c

@@ -232,10 +232,12 @@ int parse_contacts(str *_s, contact_t **_c)
 	param_hooks_t hooks;
 	str sv;
 	int n;
+	int star;
 
 	sv = *_s;
 
 	n = 0;
+	star = 0;
 	while(1) {
 		/* Allocate and clear contact structure */
 		c = (contact_t *)pkg_malloc(sizeof(contact_t));
@@ -277,6 +279,25 @@ int parse_contacts(str *_s, contact_t **_c)
 			LM_ERR("invalid contact uri\n");
 			goto error;
 		}
+		if(c->uri.len == 1) {
+			if(c->uri.s[0] == '*') {
+				if(star == 1) {
+					LM_ERR("too many star contacts - index %d\n", n);
+					goto error;
+				} else {
+					star = 1;
+				}
+			} else {
+				LM_ERR("contact uri size 1 is too short - index %d\n", n);
+				goto error;
+			}
+		} else if(c->uri.len < 3) {
+			/* minimum length 's:a' (s - schema; a - address) */
+			LM_ERR("contact uri size %d is too short - index %d\n", n,
+					c->uri.len);
+			goto error;
+		}
+
 		if(_s->len == 0)
 			goto ok;