From: Aki Tuomi Date: Wed, 22 Apr 2020 11:48:28 +0000 (+0300) Subject: stats: metrics - Use str_sanitize_utf8 to create submetric name X-Git-Tag: 2.3.11.2~235 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f2dc184d308e41b380f071449d29e04a9b649b51;p=thirdparty%2Fdovecot%2Fcore.git stats: metrics - Use str_sanitize_utf8 to create submetric name 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. --- diff --git a/src/stats/stats-metrics.c b/src/stats/stats-metrics.c index a66203f980..d996837924 100644 --- a/src/stats/stats-metrics.c +++ b/src/stats/stats-metrics.c @@ -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; }