avoid dereferencing NULL options; handle config index collisions
Costa Tsaousis (ktsaou) committed
Feb 26, 2017 at 01:48 UTC
970ce01a5a96c8c8fc94d433e9ef18c76e54e717
2 files changed
+24
-19
src/appconfig.c
+10
-5
@@ -157,8 +157,7 @@ static inline struct section *appconfig_section_create(struct config *root, cons
157
// ----------------------------------------------------------------------------
158
// config name-value methods
159
160
-static inline struct config_option *appconfig_value_create(struct section *co, const char *name, const char *value)
161
-{
160
+static inline struct config_option *appconfig_value_create(struct section *co, const char *name, const char *value) {
161
debug(D_CONFIG, "Creating config entry for name '%s', value '%s', in section '%s'.", name, value, co->name);
162
163
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
165
cv->hash = simple_hash(cv->name);
166
cv->value = strdupz(value);
167
169
- if(unlikely(appconfig_option_index_add(co, cv) != cv))
170
- error("INTERNAL ERROR: indexing of config '%s' in section '%s': already exists.", cv->name, co->name);
168
+ struct config_option *found = appconfig_option_index_add(co, cv);
169
+ if(found != cv) {
170
+ error("indexing of config '%s' in section '%s': already exists - using the existing one.", cv->name, co->name);
171
+ freez(cv->value);
172
+ freez(cv->name);
173
+ freez(cv);
174
+ return found;
175
+ }
176
177
config_section_wrlock(co);
178
struct config_option *cv2 = co->values;
@@ -240,7 +245,7 @@ int appconfig_move(struct config *root, const char *section_old, const char *nam
245
co_new->values = cv_new;
246
247
if(unlikely(appconfig_option_index_add(co_new, cv_old) != cv_old))
243
- error("INTERNAL ERROR: indexing of config '%s' in section '%s', already exists.", cv_old->name, co_new->name);
248
+ error("INTERNAL ERROR: re-indexing of config '%s' in section '%s', already exists.", cv_old->name, co_new->name);
249
250
ret = 0;
251
src/rrdhost.c
+14
-14
@@ -202,18 +202,18 @@ RRDHOST *rrdhost_create(const char *hostname,
202
}
203
else {
204
info("Host '%s' with guid '%s' initialized"
205
- ", os: %s"
206
- ", update every: %d"
207
- ", memory mode: %s"
208
- ", history entries: %d"
209
- ", streaming: %s"
210
- " to: '%s' (api key: '%s')"
211
- ", health: %s"
212
- ", cache_dir: '%s'"
213
- ", varlib_dir: '%s'"
214
- ", health_log: '%s'"
215
- ", alarms default handler: '%s'"
216
- ", alarms default recipient: '%s'"
205
+ ", os %s"
206
+ ", update every %d"
207
+ ", memory mode %s"
208
+ ", history entries %d"
209
+ ", streaming %s"
210
+ " (to '%s' with api key '%s')"
211
+ ", health %s"
212
+ ", cache_dir '%s'"
213
+ ", varlib_dir '%s'"
214
+ ", health_log '%s'"
215
+ ", alarms default handler '%s'"
216
+ ", alarms default recipient '%s'"
217
, host->hostname
218
, host->machine_guid
219
, host->os
@@ -221,8 +221,8 @@ RRDHOST *rrdhost_create(const char *hostname,
221
, rrd_memory_mode_name(host->rrd_memory_mode)
222
, host->rrd_history_entries
223
, host->rrdpush_enabled?"enabled":"disabled"
224
- , host->rrdpush_destination
225
- , host->rrdpush_api_key
224
+ , host->rrdpush_destination?host->rrdpush_destination:""
225
+ , host->rrdpush_api_key?host->rrdpush_api_key:""
226
, host->health_enabled?"enabled":"disabled"
227
, host->cache_dir
228
, host->varlib_dir