Module: kamailio
Branch: master
Commit: 4c524547e1fdd4aa6dfa0ed0ada57b002296a258
URL:
https://github.com/kamailio/kamailio/commit/4c524547e1fdd4aa6dfa0ed0ada57b0…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2023-05-17T09:57:20+02:00
topoh: don't set 0 twice at the end of masked/unmasked call-id
- fomatting updates
---
Modified: src/modules/topoh/th_mask.c
Modified: src/modules/topoh/th_msg.c
---
Diff:
https://github.com/kamailio/kamailio/commit/4c524547e1fdd4aa6dfa0ed0ada57b0…
Patch:
https://github.com/kamailio/kamailio/commit/4c524547e1fdd4aa6dfa0ed0ada57b0…
---
diff --git a/src/modules/topoh/th_mask.c b/src/modules/topoh/th_mask.c
index 122d0935a5..7dcec50136 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; idx<ilen; idx+=3)
- {
+ for(idx=0; idx<ilen; idx+=3) {
left = ilen - idx - 1 ;
left = (left>1)?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<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;
@@ -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;
}
-
diff --git a/src/modules/topoh/th_msg.c b/src/modules/topoh/th_msg.c
index 8698b7ab5d..0bc9fda97d 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;