From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id CB5A9235 for ; Tue, 18 Jul 2017 11:43:49 +0200 (CEST) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jul 2017 02:43:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,377,1496127600"; d="scan'208";a="126394801" Received: from rhorton-mobl1.ger.corp.intel.com (HELO FC23.ir.intel.com) ([163.33.230.130]) by orsmga005.jf.intel.com with ESMTP; 18 Jul 2017 02:43:47 -0700 From: Remy Horton To: dev@dpdk.org Date: Tue, 18 Jul 2017 10:43:47 +0100 Message-Id: <20170718094347.5387-1-remy.horton@intel.com> X-Mailer: git-send-email 2.9.4 Subject: [dpdk-dev] [PATCH v1] metrics: fix missing NULL termination X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Jul 2017 09:43:50 -0000 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 --- lib/librte_metrics/rte_metrics.c | 4 +++- lib/librte_metrics/rte_metrics.h | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/librte_metrics/rte_metrics.c b/lib/librte_metrics/rte_metrics.c index 6e61f9b..b66a72b 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 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.9.4