Browse code

jansson: use the core macros for ending string value with '\0' and to restore

fix #2327

Victor Seva authored on 14/05/2020 08:41:06
Showing 1 changed files
... ...
@@ -26,6 +26,7 @@
26 26
 
27 27
 #include "../../core/mod_fix.h"
28 28
 #include "../../core/lvalue.h"
29
+#include "../../core/str.h"
29 30
 
30 31
 #include "jansson_path.h"
31 32
 #include "jansson_funcs.h"
... ...
@@ -33,13 +34,13 @@
33 34
 
34 35
 int janssonmod_get_helper(sip_msg_t* msg, str *path_s, str *src_s, pv_spec_t *dst_pv)
35 36
 {
36
-
37
+	char c;
37 38
 	pv_value_t dst_val;
38 39
 	json_t* json = NULL;
39 40
 	json_error_t parsing_error;
40
-
41
+	STR_VTOZ(src_s->s[src_s->len], c);
41 42
 	json = json_loads(src_s->s, JSON_REJECT_DUPLICATES, &parsing_error);
42
-
43
+	STR_ZTOV(src_s->s[src_s->len], c);
43 44
 	if(!json) {
44 45
 		ERR("failed to parse json: %.*s\n", src_s->len, src_s->s);
45 46
 		ERR("json error at line %d, col %d: %s\n",
... ...
@@ -98,7 +99,7 @@ int janssonmod_set(unsigned int append, struct sip_msg* msg, char* type_in,
98 99
 	str type_s;
99 100
 	str value_s;
100 101
 	str path_s;
101
-
102
+	char c;
102 103
 	pv_spec_t* result_pv;
103 104
 	pv_value_t result_val;
104 105
 
... ...
@@ -126,14 +127,11 @@ int janssonmod_set(unsigned int append, struct sip_msg* msg, char* type_in,
126 127
 		result_val.rs.len = strlen("{}");
127 128
 	}
128 129
 
129
-/*
130
-	ALERT("type is: %.*s\n", type_s.len, type_s.s);
131
-	ALERT("path is: %.*s\n", path_s.len, path_s.s);
132
-	ALERT("value is: %.*s\n", value_s.len, value_s.s);
133
-	ALERT("result is: %.*s\n", result_val.rs.len, result_val.rs.s);
134
-*/
135 130
 
136
-	char* result = result_val.rs.s;
131
+	LM_DBG("type is: %.*s\n", type_s.len, type_s.s);
132
+	LM_DBG("path is: %.*s\n", path_s.len, path_s.s);
133
+	LM_DBG("value is: %.*s\n", value_s.len, value_s.s);
134
+	LM_DBG("result is: %.*s\n", result_val.rs.len, result_val.rs.s);
137 135
 
138 136
 	json_t* result_json = NULL;
139 137
 	json_t* value = NULL;
... ...
@@ -143,14 +141,18 @@ int janssonmod_set(unsigned int append, struct sip_msg* msg, char* type_in,
143 141
 
144 142
 	/* check the type */
145 143
 	if(STR_EQ_STATIC(type_s, "object") || STR_EQ_STATIC(type_s, "obj")){
144
+		STR_VTOZ(value_s.s[value_s.len], c);
146 145
 		value = json_loads(value_s.s, JSON_REJECT_DUPLICATES, &parsing_error);
146
+		STR_ZTOV(value_s.s[value_s.len], c);
147 147
 		if(value && !json_is_object(value)) {
148 148
 			ERR("value to add is not an object - \"%s\"\n", path_s.s);
149 149
 			goto fail;
150 150
 		}
151 151
 
152 152
 	}else if(STR_EQ_STATIC(type_s, "array")) {
153
+		STR_VTOZ(value_s.s[value_s.len], c);
153 154
 		value = json_loads(value_s.s, JSON_REJECT_DUPLICATES, &parsing_error);
155
+		STR_ZTOV(value_s.s[value_s.len], c);
154 156
 		if(value && !json_is_array(value)) {
155 157
 			ERR("value to add is not an array - \"%s\"\n", path_s.s);
156 158
 			goto fail;
... ...
@@ -211,9 +213,9 @@ int janssonmod_set(unsigned int append, struct sip_msg* msg, char* type_in,
211 213
 	}
212 214
 
213 215
 	char* path = path_s.s;
214
-
215
-	result_json = json_loads(result, JSON_REJECT_DUPLICATES, &parsing_error);
216
-
216
+	STR_VTOZ(result_val.rs.s[result_val.rs.len], c);
217
+	result_json = json_loads(result_val.rs.s, JSON_REJECT_DUPLICATES, &parsing_error);
218
+	STR_ZTOV(result_val.rs.s[result_val.rs.len], c);
217 219
 	if(!result_json) {
218 220
 		ERR("result has json error at line %d: %s\n",
219 221
 				parsing_error.line, parsing_error.text);
... ...
@@ -240,6 +242,7 @@ fail:
240 242
 
241 243
 int janssonmod_array_size(struct sip_msg* msg, char* path_in, char* src_in, char* dst)
242 244
 {
245
+	char c;
243 246
 	str src_s;
244 247
 	str path_s;
245 248
 	pv_spec_t *dst_pv;
... ...
@@ -259,9 +262,9 @@ int janssonmod_array_size(struct sip_msg* msg, char* path_in, char* src_in, char
259 262
 
260 263
 	json_t* json = NULL;
261 264
 	json_error_t parsing_error;
262
-
265
+	STR_VTOZ(src_s.s[src_s.len], c);
263 266
 	json = json_loads(src_s.s, JSON_REJECT_DUPLICATES, &parsing_error);
264
-
267
+	STR_ZTOV(src_s.s[src_s.len], c);
265 268
 	if(!json) {
266 269
 		ERR("json error at line %d: %s\n",
267 270
 				parsing_error.line, parsing_error.text);