]> arthur.barton.de Git - netdata.git/commitdiff
avoid dereferencing NULL options; handle config index collisions
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 25 Feb 2017 23:48:57 +0000 (01:48 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 25 Feb 2017 23:48:57 +0000 (01:48 +0200)
src/appconfig.c
src/rrdhost.c

index c628922c2d12bc4b142b7755b66d566a65f6058a..50e4c31fbdcb017d81874c5af7efabc258365f69 100644 (file)
@@ -157,8 +157,7 @@ static inline struct section *appconfig_section_create(struct config *root, cons
 // ----------------------------------------------------------------------------
 // config name-value methods
 
-static inline struct config_option *appconfig_value_create(struct section *co, const char *name, const char *value)
-{
+static inline struct config_option *appconfig_value_create(struct section *co, const char *name, const char *value) {
     debug(D_CONFIG, "Creating config entry for name '%s', value '%s', in section '%s'.", name, value, co->name);
 
     struct config_option *cv = callocz(1, sizeof(struct config_option));
@@ -166,8 +165,14 @@ static inline struct config_option *appconfig_value_create(struct section *co, c
     cv->hash = simple_hash(cv->name);
     cv->value = strdupz(value);
 
-    if(unlikely(appconfig_option_index_add(co, cv) != cv))
-        error("INTERNAL ERROR: indexing of config '%s' in section '%s': already exists.", cv->name, co->name);
+    struct config_option *found = appconfig_option_index_add(co, cv);
+    if(found != cv) {
+        error("indexing of config '%s' in section '%s': already exists - using the existing one.", cv->name, co->name);
+        freez(cv->value);
+        freez(cv->name);
+        freez(cv);
+        return found;
+    }
 
     config_section_wrlock(co);
     struct config_option *cv2 = co->values;
@@ -240,7 +245,7 @@ int appconfig_move(struct config *root, const char *section_old, const char *nam
     co_new->values = cv_new;
 
     if(unlikely(appconfig_option_index_add(co_new, cv_old) != cv_old))
-        error("INTERNAL ERROR: indexing of config '%s' in section '%s', already exists.", cv_old->name, co_new->name);
+        error("INTERNAL ERROR: re-indexing of config '%s' in section '%s', already exists.", cv_old->name, co_new->name);
 
     ret = 0;
 
index c67de6b47ff81a02f3d71acd17a24b0d05c5a59e..81c695452999758feb44bfa5ac4974f50005d756 100644 (file)
@@ -202,18 +202,18 @@ RRDHOST *rrdhost_create(const char *hostname,
     }
     else {
         info("Host '%s' with guid '%s' initialized"
-                     ", os: %s"
-                     ", update every: %d"
-                     ", memory mode: %s"
-                     ", history entries: %d"
-                     ", streaming: %s"
-                     " to: '%s' (api key: '%s')"
-                     ", health: %s"
-                     ", cache_dir: '%s'"
-                     ", varlib_dir: '%s'"
-                     ", health_log: '%s'"
-                     ", alarms default handler: '%s'"
-                     ", alarms default recipient: '%s'"
+                     ", os %s"
+                     ", update every %d"
+                     ", memory mode %s"
+                     ", history entries %d"
+                     ", streaming %s"
+                     " (to '%s' with api key '%s')"
+                     ", health %s"
+                     ", cache_dir '%s'"
+                     ", varlib_dir '%s'"
+                     ", health_log '%s'"
+                     ", alarms default handler '%s'"
+                     ", alarms default recipient '%s'"
              , host->hostname
              , host->machine_guid
              , host->os
@@ -221,8 +221,8 @@ RRDHOST *rrdhost_create(const char *hostname,
              , rrd_memory_mode_name(host->rrd_memory_mode)
              , host->rrd_history_entries
              , host->rrdpush_enabled?"enabled":"disabled"
-             , host->rrdpush_destination
-             , host->rrdpush_api_key
+             , host->rrdpush_destination?host->rrdpush_destination:""
+             , host->rrdpush_api_key?host->rrdpush_api_key:""
              , host->health_enabled?"enabled":"disabled"
              , host->cache_dir
              , host->varlib_dir