2
0
Эх сурвалжийг харах

topoh: don't set 0 twice at the end of masked/unmasked call-id

- fomatting updates

(cherry picked from commit 4c524547e1fdd4aa6dfa0ed0ada57b002296a258)
Daniel-Constantin Mierla 2 жил өмнө
parent
commit
520d1b4acb

+ 13 - 15
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;
 }
 
-

+ 0 - 5
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;