]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
Add checking if the percent argument is correct
authorBarbara Kaczorowska <bkjg@google.com>
Tue, 18 Aug 2020 09:49:37 +0000 (09:49 +0000)
committerBarbara Kaczorowska <bkjg@google.com>
Wed, 19 Aug 2020 07:42:08 +0000 (07:42 +0000)
This commit will add checking if the percent argument in
uc_get_percentile and uc_get_percentile_by_name functions is correct,
i.e. is not smaller than zero and not greater than 100.

src/daemon/utils_cache.c

index 10a4ec48997d23bb6042441747197d638c941bd1..0f85c543839b1694e3465b43c7d152c6ba4d1820 100644 (file)
@@ -126,7 +126,6 @@ static void cache_free(cache_entry_t *ce) {
 
 static int uc_insert(metric_t const *m, char const *key) {
   /* `cache_lock' has been locked by `uc_update' */
-
   char *key_copy = strdup(key);
   if (key_copy == NULL) {
     ERROR("uc_insert: strdup failed.");
@@ -445,6 +444,11 @@ int uc_set_callbacks_mask(const char *name, unsigned long mask) {
 
 int uc_get_percentile_by_name(const char *name, gauge_t *ret_values,
                               double percent) {
+  if (percent < 0 || percent > 100) {
+    ERROR("uc_get_percentile_by_name: Illegal percent %lf.", percent);
+    return -1;
+  }
+
   cache_entry_t *ce = NULL;
   int status = 0;
 
@@ -480,6 +484,11 @@ int uc_get_percentile(metric_t const *m, gauge_t *ret, double percent) {
     return -1;
   }
 
+  if (percent < 0 || percent > 100) {
+    ERROR("uc_get_percentile: Illegal percent %lf.", percent);
+    return -1;
+  }
+
   strbuf_t buf = STRBUF_CREATE;
   int status = metric_identity(&buf, m);
   if (status != 0) {