]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
stats: metrics - Use str_sanitize_utf8 to create submetric name
authorAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 22 Apr 2020 11:48:28 +0000 (14:48 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 22 Apr 2020 12:11:04 +0000 (15:11 +0300)
This was before sanitized to ascii letters and numbers. It is
foreseeable that e.g. usernames can contain utf-8 in future
so better retain it as utf-8 here.

src/stats/stats-metrics.c

index a66203f980f3aa956dd6946f06ce4699c7790ff1..d9968379241a5da0d50ee7883646f0ddefb1f7e4 100644 (file)
@@ -3,6 +3,7 @@
 #include "stats-common.h"
 #include "array.h"
 #include "str.h"
+#include "str-sanitize.h"
 #include "stats-dist.h"
 #include "time-util.h"
 #include "event-filter.h"
@@ -26,23 +27,6 @@ stats_metric_event(struct metric *metric, struct event *event, pool_t pool);
 static struct metric *
 stats_metric_sub_metric_alloc(struct metric *metric, const char *name, pool_t pool);
 
-/* This does not need to be unique as it's a display name */
-static const char *sub_metric_name_create(pool_t pool, const char *name)
-{
-       string_t *sub_name = str_new(pool, 32);
-       /* use up to 32 bytes */
-       for (const char *p = name; *p != '\0' && sub_name->used < 32;
-           p++) {
-               char c = *p;
-               if (!i_isalnum(c))
-                       c = '_';
-               else
-                       c = i_tolower(c);
-               str_append_c(sub_name, c);
-       }
-       return str_c(sub_name);
-}
-
 static void
 stats_metric_settings_to_query(const struct stats_metric_settings *set,
                               struct event_filter_query *query_r)
@@ -352,7 +336,7 @@ stats_metric_sub_metric_alloc(struct metric *metric, const char *name, pool_t po
        array_append_zero(&fields);
        sub_metric = stats_metric_alloc(pool, metric->name, metric->set,
                                        array_idx(&fields, 0));
-       sub_metric->sub_name = sub_metric_name_create(pool, name);
+       sub_metric->sub_name = p_strdup(pool, str_sanitize_utf8(name, 32));
        array_append(&metric->sub_metrics, &sub_metric, 1);
        return sub_metric;
 }