remove invalid characters from json strings: context and title; fixes #2740
Costa Tsaousis (ktsaou) committed
Sep 15, 2017 at 12:20 UTC
846e4661f75028aaea0ffd1a912dff6b721b3bbf
2 files changed
+13
-3
src/common.c
+12
-3
@@ -227,9 +227,18 @@ void json_escape_string(char *dst, const char *src, size_t size) {
227
}
228
229
void json_fix_string(char *s) {
230
- for( ; *s ;s++) {
231
- if(unlikely(*s == '\\')) *s = '/';
232
- else if(unlikely(*s == '"')) *s = '\'';
230
+ unsigned char c;
231
+ while((c = (unsigned char)*s)) {
232
+ if(unlikely(c == '\\'))
233
+ *s++ = '/';
234
+ else if(unlikely(c == '"'))
235
+ *s++ = '\'';
236
+ else if(unlikely(isspace(c) || iscntrl(c)))
237
+ *s++ = ' ';
238
+ else if(unlikely(!isprint(c) || c > 127))
239
+ *s++ = '_';
240
+ else
241
+ s++;
242
}
243
}
244
src/rrdset.c
+1
@@ -586,6 +586,7 @@ RRDSET *rrdset_create_custom(
586
st->units = config_get(st->config_section, "units", units?units:"");
587
588
st->context = config_get(st->config_section, "context", context?context:st->id);
589
+ json_fix_string(st->context);
590
st->hash_context = simple_hash(st->context);
591
592
st->priority = config_get_number(st->config_section, "priority", priority);