Browse Source

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

prevent crash
Costa Tsaousis 2 years ago
parent
commit
84b07e6e28
1 changed files with 10 additions and 0 deletions
  1. 10 0
      database/rrdcontext.c

+ 10 - 0
database/rrdcontext.c

@@ -2377,6 +2377,11 @@ static inline int rrdcontext_to_json_callback(const char *id, void *value, void
 }
 
 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) {
+    if(!host->rrdctx) {
+        error("%s(): request for host '%s' that does not have rrdcontexts initialized.", __FUNCTION__, host->hostname);
+        return HTTP_RESP_NOT_FOUND;
+    }
+
     RRDCONTEXT_ACQUIRED *rca = (RRDCONTEXT_ACQUIRED *)dictionary_get_and_acquire_item((DICTIONARY *)host->rrdctx, context);
     if(!rca) return HTTP_RESP_NOT_FOUND;
 
@@ -2412,6 +2417,11 @@ int rrdcontext_to_json(RRDHOST *host, BUFFER *wb, time_t after, time_t before, R
 }
 
 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) {
+    if(!host->rrdctx) {
+        error("%s(): request for host '%s' that does not have rrdcontexts initialized.", __FUNCTION__, host->hostname);
+        return HTTP_RESP_NOT_FOUND;
+    }
+
     char node_uuid[UUID_STR_LEN] = "";
 
     if(host->node_id)