Browse code

topoh: check if via param has the expected prefix, otherwise skip

- GH #2437

(cherry picked from commit 046126b4a90090bf5b8f9b517ba5218793e6b973)
(cherry picked from commit c8c884c4db353d4fac83752a494989e699fc36ff)

Daniel-Constantin Mierla authored on 11/08/2020 10:36:02
Showing 1 changed files
... ...
@@ -408,7 +408,7 @@ int th_unmask_via(sip_msg_t *msg, str *cookie)
408 408
 				if (th_uri_prefix_checks && (via->host.len!=th_ip.len
409 409
 						|| strncasecmp(via->host.s, th_ip.s, th_ip.len)!=0))
410 410
 				{
411
-					LM_DBG("via %d is not encoded",i);
411
+					LM_DBG("via %d is not encoded - skip\n",i);
412 412
 					continue;
413 413
 				}
414 414
 
... ...
@@ -418,9 +418,16 @@ int th_unmask_via(sip_msg_t *msg, str *cookie)
418 418
 					LM_ERR("cannot find param in via %d\n", i);
419 419
 					return -1;
420 420
 				}
421
-				if(vp->value.len <= th_vparam_prefix.len) {
422
-					LM_ERR("invalid param len in via %d\n", i);
423
-					return -1;
421
+				if(th_vparam_prefix.len > 0) {
422
+					if(vp->value.len <= th_vparam_prefix.len) {
423
+						LM_DBG("shorter param len in via %d - skip\n", i);
424
+						continue;
425
+					}
426
+					if(strncmp(vp->value.s, th_vparam_prefix.s,
427
+									th_vparam_prefix.len) != 0) {
428
+						LM_DBG("no prefix in via %d - skip\n", i);
429
+						continue;
430
+					}
424 431
 				}
425 432
 				if(i==2) {
426 433
 					out.s = th_mask_decode(vp->value.s, vp->value.len,