diff options
author | Costa Tsaousis <costa@tsaousis.gr> | 2017-09-15 15:19:38 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-15 15:19:38 +0300 |
commit | ca19f8e6f012441e3143297a53ba2233b5d9e4c9 (patch) | |
tree | 35adef3e56cc219cc70072bc762cd9b9c9e15bf5 | |
parent | 9671757eb471b65b06c199453de619e04a0f7a6c (diff) | |
parent | 513aeb9fc1c2ba33e30567840d65dbf715cdecc4 (diff) |
Merge pull request #2741 from ktsaou/master
escape invalid characters from chart parameters
-rw-r--r-- | src/common.c | 15 | ||||
-rw-r--r-- | src/rrdset.c | 5 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/common.c b/src/common.c index aa75c198d2..5a953672d0 100644 --- a/src/common.c +++ b/src/common.c @@ -227,9 +227,18 @@ void json_escape_string(char *dst, const char *src, size_t size) { } void json_fix_string(char *s) { - for( ; *s ;s++) { - if(unlikely(*s == '\\')) *s = '/'; - else if(unlikely(*s == '"')) *s = '\''; + unsigned char c; + while((c = (unsigned char)*s)) { + if(unlikely(c == '\\')) + *s++ = '/'; + else if(unlikely(c == '"')) + *s++ = '\''; + else if(unlikely(isspace(c) || iscntrl(c))) + *s++ = ' '; + else if(unlikely(!isprint(c) || c > 127)) + *s++ = '_'; + else + s++; } } diff --git a/src/rrdset.c b/src/rrdset.c index caa427ff6f..c5168f02ed 100644 --- a/src/rrdset.c +++ b/src/rrdset.c @@ -582,10 +582,15 @@ RRDSET *rrdset_create_custom( st->chart_type = rrdset_type_id(config_get(st->config_section, "chart type", rrdset_type_name(chart_type))); st->type = config_get(st->config_section, "type", type); + st->family = config_get(st->config_section, "family", family?family:st->type); + json_fix_string(st->family); + st->units = config_get(st->config_section, "units", units?units:""); + json_fix_string(st->units); st->context = config_get(st->config_section, "context", context?context:st->id); + json_fix_string(st->context); st->hash_context = simple_hash(st->context); st->priority = config_get_number(st->config_section, "priority", priority); |