@cryptotaxi247 / netdata-1 / commits / 3b0e4ff90

health configuration variables are checked for invalid characters

Costa Tsaousis committed Aug 14, 2016 at 19:28 UTC 3b0e4ff9001f1186d1264d3265891728f44fee75
2 files changed +28 -36
src/health.c
+26 -14
@@ -1,6 +1,9 @@
1 #include "common.h"
2
3 +#define RRDSETVAR_ID_MAX 1024
4 +
5 static const char *health_default_exec = PLUGINS_DIR "/alarm.sh";
6 +int health_enabled = 1;
7
8 // ----------------------------------------------------------------------------
9 // RRDVAR management
@@ -97,8 +100,6 @@ static inline RRDVAR *rrdvar_create_and_index(const char *scope, avl_tree_lock *
100 // ----------------------------------------------------------------------------
101 // RRDSETVAR management
102
100 -#define RRDSETVAR_ID_MAX 1024
101 -
103 RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, int type, void *value, uint32_t options) {
104 debug(D_VARIABLES, "RRDVARSET create for chart id '%s' name '%s' with variable name '%s'", st->id, st->name, variable);
105 RRDSETVAR *rs = (RRDSETVAR *)callocz(1, sizeof(RRDSETVAR));
@@ -735,21 +736,28 @@ void rrdcalc_free(RRDHOST *host, RRDCALC *rc) {
736 // ----------------------------------------------------------------------------
737 // RRDCALCTEMPLATE management
738
739 +static inline int variable_fix_name(char *variable) {
740 + int fixed = 0;
741 + while(*variable) {
742 + if (!isalnum(*variable) && *variable != '.' && *variable != '_') {
743 + *variable++ = '_';
744 + fixed++;
745 + }
746 + else
747 + variable++;
748 + }
749 +
750 + return fixed;
751 +}
752 +
753 void rrdcalctemplate_link_matching(RRDSET *st) {
754 RRDCALCTEMPLATE *rt;
755
756 for(rt = st->rrdhost->templates; rt ; rt = rt->next) {
757 if(rt->hash_context == st->hash_context && !strcmp(rt->context, st->context)) {
743 - char *s, buffer[RRDSETVAR_ID_MAX + 1];
758 + char buffer[RRDSETVAR_ID_MAX + 1];
759 snprintfz(buffer, RRDSETVAR_ID_MAX, "%s.%s", st->family, rt->name);
745 - s = buffer;
746 - while(*s) {
747 - if (!isalnum(*s) && *s != '.' && *s != '_')
748 - *s++ = '_';
749 - else
750 - s++;
751 - }
752 -
760 + variable_fix_name(buffer);
761 rrdcalc_create(st->rrdhost, buffer, st->id,
762 rt->dimensions, rt->group, rt->after, rt->before, rt->update_every, rt->options,
763 rt->green, rt->red, rt->exec,
@@ -1115,11 +1123,13 @@ int health_readfile(const char *path, const char *filename) {
1123 rt = NULL;
1124 }
1125
1118 - // FIXME: make sure the value does not any operators or spaces
1126 rc = callocz(1, sizeof(RRDCALC));
1127 rc->name = strdupz(value);
1128 rc->hash = simple_hash(rc->name);
1129 rc->source = health_source_file(line, path, filename);
1130 +
1131 + if(variable_fix_name(rc->name))
1132 + error("Health configuration renamed alarm '%s' to '%s'", value, rc->name);
1133 }
1134 else if(hash == hash_template && !strcasecmp(key, HEALTH_TEMPLATE_KEY)) {
1135 if(rc) {
@@ -1131,11 +1141,13 @@ int health_readfile(const char *path, const char *filename) {
1141 if(rt && !rrdcalctemplate_add(&localhost, rt))
1142 rrdcalctemplate_free(&localhost, rt);
1143
1134 - // FIXME: make sure the value does not any operators or spaces
1144 rt = callocz(1, sizeof(RRDCALCTEMPLATE));
1145 rt->name = strdupz(value);
1146 rt->hash_name = simple_hash(rt->name);
1147 rt->source = health_source_file(line, path, filename);
1148 +
1149 + if(variable_fix_name(rt->name))
1150 + error("Health configuration renamed template '%s' to '%s'", value, rt->name);
1151 }
1152 else if(rc) {
1153 if(hash == hash_on && !strcasecmp(key, HEALTH_ON_KEY)) {
@@ -1355,7 +1367,7 @@ void health_init(void) {
1367
1368 char *path;
1369
1358 - if(!config_get_boolean("health", "enabled", 1)) {
1370 + if(!(health_enabled = config_get_boolean("health", "enabled", 1))) {
1371 debug(D_HEALTH, "Health is disabled.");
1372 return;
1373 }
src/health.h
+2 -22
@@ -1,29 +1,9 @@
1 #ifndef NETDATA_HEALTH_H
2 #define NETDATA_HEALTH_H
3
4 -extern int rrdvar_compare(void *a, void *b);
4 +extern int health_enabled;
5
6 -/*
7 - * RRDVAR
8 - * a variable
9 - *
10 - * There are 4 scopes: local (chart), context, host and global variables
11 - *
12 - * Standard global variables:
13 - * $now
14 - *
15 - * Standard host variables:
16 - * - none -
17 - *
18 - * Standard context variables:
19 - * - none -
20 - *
21 - * Standard local variables:
22 - * $last_updated
23 - * $last_collected_value
24 - * $last_value
25 - *
26 - */
6 +extern int rrdvar_compare(void *a, void *b);
7
8 #define RRDVAR_TYPE_CALCULATED 1
9 #define RRDVAR_TYPE_TIME_T 2