diff options
author | thiagoftsm <thiagoftsm@gmail.com> | 2020-01-16 14:31:01 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-16 14:31:01 +0000 |
commit | 1db77eb15e802ffb111300a1a20c0fcdfa26d6e7 (patch) | |
tree | cf681b395eef9dd796973181572e2db59bdd76fe /database/rrdhost.c | |
parent | 81251da72c50c0b9efe9efced75452069c4834cb (diff) |
Restrict quotes in label values (#7594)
* quotes_labels: Restrict quotes
This commit brings the restriction for the values that will not be allowed to have quotes
* quotes_labels: Documentation
This commit brings update to the documentation
* quotes_labels: Missing comma
This commit brings a missing comma for the documentation
* quotes_labels: Rename variable
The variable was renamed to let code more readable
* quotes_labels: call function
There was a missing call in our utf-8 function, this commit fixes this
* quotes_labels: Remove segmentation fault
The previous code could result in a segmentation fault depending of the label size,
this commit removes this possibility
* quotes_labels: remove unecessary UTF-8
Considering that I am testing all addresses, I am removing the UTf-8 call
* quotes_labels: Rename variable
This commit renames variable according to documentation
* quotes_labels: Comparison to function
this commit converts the comparison to test labels to an unique function
* quotes_labels: Restore name
The new name was breaking compatibility with the structure value
* quotes_labels: Rename function
Rename the function to keep an unique pattern
* quotes_labels: Restore previous utf-8 library
* quotes_labels: Remove missing file
* quotes_labels: Fix grammar
Fix grammar documentation
* quotes_labels: Missing comparison
This commit brings the two missing characters that must be rejected from value
* quotes_labels: Fix grammar again
Fix grammar documentation
Diffstat (limited to 'database/rrdhost.c')
-rw-r--r-- | database/rrdhost.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/database/rrdhost.c b/database/rrdhost.c index a7fac8569b..4eb8601396 100644 --- a/database/rrdhost.c +++ b/database/rrdhost.c @@ -710,6 +710,18 @@ void rrdhost_save_charts(RRDHOST *host) { rrdhost_unlock(host); } +static int is_valid_label_value(char *value) { + while(*value) { + if(*value == '"' || *value == '\'' || *value == '*' || *value == '!') { + return 0; + } + + value++; + } + + return 1; +} + static int is_valid_label_key(char *key) { //Prometheus exporter if(!strcmp(key, "chart") || !strcmp(key, "family") || !strcmp(key, "dimension")) @@ -784,6 +796,10 @@ struct label *load_auto_labels() return label_list; } +static inline int is_valid_label_config_option(char *name, char *value) { + return (is_valid_label_key(name) && is_valid_label_value(value) && strcmp(name, "from environment") && strcmp(name, "from kubernetes pods") ); + } + struct label *load_config_labels() { int status = config_load(NULL, 1, CONFIG_SECTION_HOST_LABEL); @@ -798,13 +814,12 @@ struct label *load_config_labels() config_section_wrlock(co); struct config_option *cv; for(cv = co->values; cv ; cv = cv->next) { - char *name = cv->name; - if(is_valid_label_key(name) && strcmp(name, "from environment") && strcmp(name, "from kubernetes pods") ) { - l = add_label_to_list(l, name, cv->value, LABEL_SOURCE_NETDATA_CONF); + if( is_valid_label_config_option(cv->name, cv->value)) { + l = add_label_to_list(l, cv->name, cv->value, LABEL_SOURCE_NETDATA_CONF); cv->flags |= CONFIG_VALUE_USED; } else { error("LABELS: It was not possible to create the label '%s' because it contains invalid character(s) or values." - , name); + , cv->name); } } config_section_unlock(co); |