From 4c524547e1fdd4aa6dfa0ed0ada57b002296a258 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Wed, 17 May 2023 09:57:20 +0200 Subject: [PATCH] topoh: don't set 0 twice at the end of masked/unmasked call-id - fomatting updates --- src/modules/topoh/th_mask.c | 28 +++++++++++++--------------- src/modules/topoh/th_msg.c | 5 ----- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/modules/topoh/th_mask.c b/src/modules/topoh/th_mask.c index 122d0935a5e..7dcec501360 100644 --- a/src/modules/topoh/th_mask.c +++ b/src/modules/topoh/th_mask.c @@ -96,19 +96,20 @@ char* th_mask_encode(char *in, int ilen, str *prefix, int *olen) *olen = (((ilen+2)/3)<<2) + ((prefix!=NULL&&prefix->len>0)?prefix->len:0); out = (char*)pkg_malloc((*olen+1)*sizeof(char)); - if(out==NULL) - { + if(out==NULL) { PKG_MEM_ERROR; *olen = 0; return NULL; } + + /* set 0 at the end of the value */ memset(out, 0, (*olen+1)*sizeof(char)); - if(prefix!=NULL&&prefix->len>0) + if(prefix!=NULL&&prefix->len>0) { memcpy(out, prefix->s, prefix->len); + } p = out + (int)((prefix!=NULL&&prefix->len>0)?prefix->len:0); - for(idx=0; idx1)?2:left; @@ -149,24 +150,21 @@ char* th_mask_decode(char *in, int ilen, str *prefix, int extra, int *olen) out = (char*)pkg_malloc((*olen+1+extra)*sizeof(char)); - if(out==NULL) - { + if(out==NULL) { PKG_MEM_ERROR; *olen = 0; return NULL; } + /* set 0 at the end of the value */ memset(out, 0, (*olen+1+extra)*sizeof(char)); end = ilen - n; i = (prefix!=NULL&&prefix->len>0)?prefix->len:0; - for(idx=0; i> n) & 0xff); + } } return out; } - diff --git a/src/modules/topoh/th_msg.c b/src/modules/topoh/th_msg.c index 8698b7ab5d9..0bc9fda97d9 100644 --- a/src/modules/topoh/th_msg.c +++ b/src/modules/topoh/th_msg.c @@ -562,8 +562,6 @@ int th_mask_callid_str(str *icallid, str *ocallid) LM_ERR("cannot encode call-id\n"); return -1; } - - out.s[out.len] = '\0'; ocallid->s = out.s; ocallid->len = out.len; @@ -572,7 +570,6 @@ int th_mask_callid_str(str *icallid, str *ocallid) int th_unmask_callid_str(str *icallid, str *ocallid) { - str out; if(th_param_mask_callid==0) @@ -597,8 +594,6 @@ int th_unmask_callid_str(str *icallid, str *ocallid) LM_ERR("failed to decode call-id\n"); return -2; } - - out.s[out.len] = '\0'; ocallid->s = out.s; ocallid->len = out.len;