Browse code

core: use same condition for extra_params in create_via_hf()

(cherry picked from commit 62e822ce25e93a8183dd9e5e1fee517143849a6a)
(cherry picked from commit 9d8b937f832334be2660f95c9886ae3da6b60968)

Daniel-Constantin Mierla authored on 07/04/2021 07:53:39 • Henning Westerholt committed on 22/10/2021 11:42:28
Showing 1 changed files
... ...
@@ -2948,12 +2948,14 @@ char* create_via_hf(unsigned int *len,
2948 2948
 		/* params so far + ';rport' + '\0' */
2949 2949
 		via = (char*)pkg_malloc(extra_params.len+RPORT_LEN);
2950 2950
 		if(via==0) {
2951
-		        PKG_MEM_ERROR;
2951
+			PKG_MEM_ERROR;
2952 2952
 			if (extra_params.s) pkg_free(extra_params.s);
2953 2953
 			return 0;
2954 2954
 		}
2955
-		if(extra_params.len!=0) {
2955
+		if(extra_params.s!=NULL && extra_params.len>0) {
2956 2956
 			memcpy(via, extra_params.s, extra_params.len);
2957
+		}
2958
+		if(extra_params.s!=NULL) {
2957 2959
 			pkg_free(extra_params.s);
2958 2960
 		}
2959 2961
 		memcpy(via + extra_params.len, RPORT, RPORT_LEN-1);
... ...
@@ -2974,8 +2976,10 @@ char* create_via_hf(unsigned int *len,
2974 2976
 				if (extra_params.s) pkg_free(extra_params.s);
2975 2977
 				return 0;
2976 2978
 			}
2977
-			if(extra_params.len != 0) {
2979
+			if(extra_params.s!=NULL && extra_params.len>0) {
2978 2980
 				memcpy(via, extra_params.s, extra_params.len);
2981
+			}
2982
+			if(extra_params.s!=NULL) {
2979 2983
 				pkg_free(extra_params.s);
2980 2984
 			}
2981 2985
 			memcpy(via + extra_params.len, sbuf, slen);
... ...
@@ -2994,12 +2998,14 @@ char* create_via_hf(unsigned int *len,
2994 2998
 		if(xparams.len>0) {
2995 2999
 			via = (char*)pkg_malloc(extra_params.len+xparams.len+2);
2996 3000
 			if(via==0) {
2997
-			        PKG_MEM_ERROR;
3001
+				PKG_MEM_ERROR;
2998 3002
 				if (extra_params.s) pkg_free(extra_params.s);
2999 3003
 				return 0;
3000 3004
 			}
3001
-			if(extra_params.len != 0) {
3005
+			if(extra_params.s!=NULL && extra_params.len>0) {
3002 3006
 				memcpy(via, extra_params.s, extra_params.len);
3007
+			}
3008
+			if(extra_params.s!=NULL) {
3003 3009
 				pkg_free(extra_params.s);
3004 3010
 			}
3005 3011
 			/* add ';' between via parameters */