From patchwork Tue Feb 20 14:50:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remy Horton X-Patchwork-Id: 35305 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1189D1B172; Tue, 20 Feb 2018 15:50:05 +0100 (CET) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 12261A48A for ; Tue, 20 Feb 2018 15:50:03 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Feb 2018 06:50:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,539,1511856000"; d="scan'208";a="19735909" Received: from rhorton-mobl1.ger.corp.intel.com (HELO FC23.ir.intel.com) ([163.33.231.16]) by orsmga006.jf.intel.com with ESMTP; 20 Feb 2018 06:50:02 -0800 From: Remy Horton To: dev@dpdk.org Date: Tue, 20 Feb 2018 14:50:01 +0000 Message-Id: <20180220145001.18442-1-remy.horton@intel.com> X-Mailer: git-send-email 2.9.5 Subject: [dpdk-dev] [PATCH v1] metrics: fix potential 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Fixes a potential memory overrun detected by Coverity. This overrun cannot currently happen in practice because rte_metrics_reg_names() explicitly forces the last name character to be a NULL terminator. This patch adds the same enforcement to rte_metrics_get_names() in order to correct the warning. Coverity issue: 143434 Fixes: 349950ddb9c5 ("metrics: add information metrics library") Signed-off-by: Remy Horton --- lib/librte_metrics/rte_metrics.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/librte_metrics/rte_metrics.c b/lib/librte_metrics/rte_metrics.c index 556ae1b..958ef3d 100644 --- a/lib/librte_metrics/rte_metrics.c +++ b/lib/librte_metrics/rte_metrics.c @@ -214,10 +214,15 @@ rte_metrics_get_names(struct rte_metric_name *names, rte_spinlock_unlock(&stats->lock); return return_value; } - for (idx_name = 0; idx_name < stats->cnt_stats; idx_name++) + for (idx_name = 0; idx_name < stats->cnt_stats; idx_name++) { strncpy(names[idx_name].name, stats->metadata[idx_name].name, RTE_METRICS_MAX_NAME_LEN); + /* Enforce NULL-termination. The source string should already + * be NULL-terminated, so this is to quieten lint checks.. + */ + names[idx_name].name[RTE_METRICS_MAX_NAME_LEN - 1] = '\0'; + } } return_value = stats->cnt_stats; rte_spinlock_unlock(&stats->lock);