Ver Fonte

topoh: improve checks for via header processing

(cherry picked from commit 78ccdb7ff1ebc34748092fe01ff249f5eeb661c8)
Henning Westerholt há 6 anos atrás
pai
commit
7931da0ca4
2 ficheiros alterados com 13 adições e 2 exclusões
  1. 6 0
      src/modules/topoh/th_mask.c
  2. 7 2
      src/modules/topoh/th_msg.c

+ 6 - 0
src/modules/topoh/th_mask.c

@@ -141,6 +141,12 @@ char* th_mask_decode(char *in, int ilen, str *prefix, int extra, int *olen)
 
 	*olen = (((ilen-((prefix!=NULL&&prefix->len>0)?prefix->len:0)) * 6) >> 3)
 				- n;
+
+	if (*olen<=0) {
+		LM_ERR("invalid olen parameter calculated, can't continue %d\n", *olen);
+		return NULL;
+	}
+
 	out = (char*)pkg_malloc((*olen+1+extra)*sizeof(char));
 
 	if(out==NULL)

+ 7 - 2
src/modules/topoh/th_msg.c

@@ -411,7 +411,7 @@ int th_unmask_via(sip_msg_t *msg, str *cookie)
 				else
 					out.s = th_mask_decode(vp->value.s, vp->value.len,
 							&th_vparam_prefix, 0, &out.len);
-				if(out.s==NULL)
+				if(out.s==NULL || out.len<=0)
 				{
 					LM_ERR("cannot decode via %d\n", i);
 					return -1;
@@ -945,7 +945,12 @@ int th_add_via_cookie(sip_msg_t *msg, struct via_body *via)
 	if (via->params.s) {
 		viap = via->params.s - via->hdr.s - 1;
 	} else {
-		viap = via->host.s - via->hdr.s + via->host.len;
+		if (via->host.s) {
+			viap = via->host.s - via->hdr.s + via->host.len;
+		} else {
+			LM_ERR("no via parameter and no via host, can't insert cookie\n");
+			return -1;
+		}
 		if (via->port!=0)
 			viap += via->port_str.len + 1; /* +1 for ':'*/
 	}