Skip to content

Commit

Permalink
topoh: don't set 0 twice at the end of masked/unmasked call-id
Browse files Browse the repository at this point in the history
- fomatting updates
  • Loading branch information
miconda committed May 17, 2023
1 parent 991de5e commit 4c52454
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
28 changes: 13 additions & 15 deletions src/modules/topoh/th_mask.c
Expand Up @@ -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; idx<ilen; idx+=3)
{
for(idx=0; idx<ilen; idx+=3) {
left = ilen - idx - 1 ;
left = (left>1)?2:left;

Expand Down Expand Up @@ -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<end; idx+=3)
{
for(idx=0; i<end; idx+=3) {
block = 0;
for(j=0; j<4 && i<end ; j++)
{
for(j=0; j<4 && i<end ; j++) {
c = _th_DB64[(int)in[i++]];
if(c<0)
{
if(c<0) {
LM_ERR("invalid input string\"%.*s\"\n", ilen, in);
pkg_free(out);
*olen = 0;
Expand All @@ -175,11 +173,11 @@ char* th_mask_decode(char *in, int ilen, str *prefix, int extra, int *olen)
block += c << (18 - 6*j);
}

for(j=0, n=16; j<3 && idx+j< *olen; j++, n-=8)
for(j=0, n=16; j<3 && idx+j< *olen; j++, n-=8) {
out[idx+j] = (char)((block >> n) & 0xff);
}
}

return out;
}


5 changes: 0 additions & 5 deletions src/modules/topoh/th_msg.c
Expand Up @@ -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;

Expand All @@ -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)
Expand All @@ -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;

Expand Down

0 comments on commit 4c52454

Please sign in to comment.