diff --git a/src/modules/topoh/th_mask.c b/src/modules/topoh/th_mask.c index 2c0d1aa24f6..fce9255f204 100644 --- a/src/modules/topoh/th_mask.c +++ b/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) diff --git a/src/modules/topoh/th_msg.c b/src/modules/topoh/th_msg.c index 142eda15802..a3b6ab5f298 100644 --- a/src/modules/topoh/th_msg.c +++ b/src/modules/topoh/th_msg.c @@ -419,7 +419,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; @@ -949,7 +949,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 ':'*/ }