From ae1f976ea58daf545b7bc4f509a80c2fd7d32528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Fri, 15 May 2020 15:41:14 +0200 Subject: [PATCH] Fixes #2802: Added checks to verify that no prometheus array element is left un-initialized --- include/prometheus_helpers.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/include/prometheus_helpers.h b/include/prometheus_helpers.h index b19772773..e2d9159fa 100644 --- a/include/prometheus_helpers.h +++ b/include/prometheus_helpers.h @@ -11,6 +11,8 @@ using prometheus::Counter; using prometheus::Gauge; +#define ILLFORMED_PMAP_MSG "Array element remains empty after initialization, map must be ill-formed." + /** * @brief Initalizes an array of 'prometheus::Counter*' with the data supplied in a map. * @@ -60,6 +62,13 @@ void init_prometheus_counter_array( counter_array[tg_metric] = std::addressof(metric_family->Add(metric_tags)); } + + for (const auto& array_elem : counter_array) { + if (array_elem == nullptr) { + proxy_error("init_prometheus_counter_array: " ILLFORMED_PMAP_MSG); + assert(0); + } + } } /** @@ -111,6 +120,13 @@ void init_prometheus_gauge_array( gauge_array[tg_metric] = std::addressof(metric_family->Add(metric_tags)); } + + for (const auto& array_elem : gauge_array) { + if (array_elem == nullptr) { + proxy_error("init_prometheus_gauge_array: " ILLFORMED_PMAP_MSG); + assert(0); + } + } } /** @@ -160,6 +176,13 @@ void init_prometheus_dyn_counter_array( dyn_counter_array[tg_metric] = metric_family; } + + for (const auto& array_elem : dyn_counter_array) { + if (array_elem == nullptr) { + proxy_error("init_prometheus_dyn_counter_array: " ILLFORMED_PMAP_MSG); + assert(0); + } + } } /** @@ -209,6 +232,13 @@ void init_prometheus_dyn_gauge_array( dyn_gauge_array[tg_metric] = metric_family; } + + for (const auto& array_elem : dyn_gauge_array) { + if (array_elem == nullptr) { + proxy_error("init_prometheus_dyn_gauge_array: " ILLFORMED_PMAP_MSG); + assert(0); + } + } } /**