From: Remy Horton Date: Tue, 18 Jul 2017 09:43:47 +0000 (+0100) Subject: metrics: fix name string termination X-Git-Tag: spdx-start~2472 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=fa43ac77294a1a00b1fc30514162145ca17fa766;p=dpdk.git metrics: fix name string termination The public API (struct rte_metric_name) includes the NULL terminator byte in RTE_METRICS_MAX_NAME_LENGTH but the library itself internally excludes it. This makes it possible for an application to receive an unterminated name string. Fix be enforcing the NULL termination of all name strings to the length that the public API expects. Fixes: 349950ddb9c5 ("metrics: add information metrics library") Cc: stable@dpdk.org Signed-off-by: Remy Horton --- diff --git a/lib/librte_metrics/rte_metrics.c b/lib/librte_metrics/rte_metrics.c index 6e61f9b1ba..b66a72bb09 100644 --- a/lib/librte_metrics/rte_metrics.c +++ b/lib/librte_metrics/rte_metrics.c @@ -51,7 +51,7 @@ */ struct rte_metrics_meta_s { /** Name of metric */ - char name[RTE_METRICS_MAX_NAME_LEN + 1]; + char name[RTE_METRICS_MAX_NAME_LEN]; /** Current value for metric */ uint64_t value[RTE_MAX_ETHPORTS]; /** Used for global metrics */ @@ -144,6 +144,8 @@ rte_metrics_reg_names(const char * const *names, uint16_t cnt_names) entry = &stats->metadata[idx_name + stats->cnt_stats]; strncpy(entry->name, names[idx_name], RTE_METRICS_MAX_NAME_LEN); + /* Enforce NULL-termination */ + entry->name[RTE_METRICS_MAX_NAME_LEN - 1] = '\0'; memset(entry->value, 0, sizeof(entry->value)); entry->idx_next_stat = idx_name + stats->cnt_stats + 1; } diff --git a/lib/librte_metrics/rte_metrics.h b/lib/librte_metrics/rte_metrics.h index 0fa3104ec4..297300ad2c 100644 --- a/lib/librte_metrics/rte_metrics.h +++ b/lib/librte_metrics/rte_metrics.h @@ -118,7 +118,8 @@ void rte_metrics_init(int socket_id); * is required for updating said metric's value. * * @param name - * Metric name + * Metric name. If this exceeds RTE_METRICS_MAX_NAME_LEN (including + * the NULL terminator), it is truncated. * * @return * - Zero or positive: Success (index key of new metric)