[dpdk-stable] patch 'metrics: fix name string termination' has been queued to stable release 17.05.2

Yuanhan Liu yliu at fridaylinux.org
Mon Aug 21 11:30:19 CEST 2017


Hi,

FYI, your patch has been queued to stable release 17.05.2

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 08/24/17. So please
shout if anyone has objections.

Thanks.

	--yliu

---
>From a7dd0ca5c8ba450e981892a5d40eb5126ae65b37 Mon Sep 17 00:00:00 2001
From: Remy Horton <remy.horton at intel.com>
Date: Tue, 18 Jul 2017 10:43:47 +0100
Subject: [PATCH] metrics: fix name string termination

[ upstream commit fa43ac77294a1a00b1fc30514162145ca17fa766 ]

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")

Signed-off-by: Remy Horton <remy.horton at intel.com>
---
 lib/librte_metrics/rte_metrics.c | 2 ++
 lib/librte_metrics/rte_metrics.h | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/librte_metrics/rte_metrics.c b/lib/librte_metrics/rte_metrics.c
index e9a122c..dbbad32 100644
--- a/lib/librte_metrics/rte_metrics.c
+++ b/lib/librte_metrics/rte_metrics.c
@@ -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 0fa3104..297300a 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)
-- 
2.7.4



More information about the stable mailing list