@cryptotaxi247 / netdata-1 / commits / 84b07e6e2

prevent crash on rrdcontext apis when rrdcontexts is not initialized (#13578)

prevent crash

Costa Tsaousis committed Aug 27, 2022 at 18:50 UTC 84b07e6e286ffa6db4f9f9d082e886e609bb6104
1 file changed +10
database/rrdcontext.c
+10
@@ -2377,6 +2377,11 @@ static inline int rrdcontext_to_json_callback(const char *id, void *value, void
2377 }
2378
2379 int rrdcontext_to_json(RRDHOST *host, BUFFER *wb, time_t after, time_t before, RRDCONTEXT_TO_JSON_OPTIONS options, const char *context, SIMPLE_PATTERN *chart_label_key, SIMPLE_PATTERN *chart_labels_filter, SIMPLE_PATTERN *chart_dimensions) {
2380 + if(!host->rrdctx) {
2381 + error("%s(): request for host '%s' that does not have rrdcontexts initialized.", __FUNCTION__, host->hostname);
2382 + return HTTP_RESP_NOT_FOUND;
2383 + }
2384 +
2385 RRDCONTEXT_ACQUIRED *rca = (RRDCONTEXT_ACQUIRED *)dictionary_get_and_acquire_item((DICTIONARY *)host->rrdctx, context);
2386 if(!rca) return HTTP_RESP_NOT_FOUND;
2387
@@ -2412,6 +2417,11 @@ int rrdcontext_to_json(RRDHOST *host, BUFFER *wb, time_t after, time_t before, R
2417 }
2418
2419 int rrdcontexts_to_json(RRDHOST *host, BUFFER *wb, time_t after, time_t before, RRDCONTEXT_TO_JSON_OPTIONS options, SIMPLE_PATTERN *chart_label_key, SIMPLE_PATTERN *chart_labels_filter, SIMPLE_PATTERN *chart_dimensions) {
2420 + if(!host->rrdctx) {
2421 + error("%s(): request for host '%s' that does not have rrdcontexts initialized.", __FUNCTION__, host->hostname);
2422 + return HTTP_RESP_NOT_FOUND;
2423 + }
2424 +
2425 char node_uuid[UUID_STR_LEN] = "";
2426
2427 if(host->node_id)