From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ppoornix@ecsmtp.ir.intel.com>
Received: from mga09.intel.com (mga09.intel.com [134.134.136.24])
 by dpdk.org (Postfix) with ESMTP id A892A1B39F;
 Thu, 14 Feb 2019 13:58:24 +0100 (CET)
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from fmsmga005.fm.intel.com ([10.253.24.32])
 by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;
 14 Feb 2019 04:58:23 -0800
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.58,368,1544515200"; d="scan'208";a="320348092"
Received: from irvmail001.ir.intel.com ([163.33.26.43])
 by fmsmga005.fm.intel.com with ESMTP; 14 Feb 2019 04:58:21 -0800
Received: from wgcvswdev001.ir.intel.com (wgcvswdev001.ir.intel.com
 [10.102.246.100])
 by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id
 x1ECwK3a012221; Thu, 14 Feb 2019 12:58:20 GMT
Received: from wgcvswdev001.ir.intel.com (localhost [127.0.0.1])
 by wgcvswdev001.ir.intel.com with ESMTP id x1ECvi6H014487;
 Thu, 14 Feb 2019 12:57:44 GMT
Received: (from ppoornix@localhost)
	by wgcvswdev001.ir.intel.com with œ id x1ECvi45014482;
	Thu, 14 Feb 2019 12:57:44 GMT
From: Pallantla Poornima <pallantlax.poornima@intel.com>
To: dev@dpdk.org
Cc: reshma.pattan@intel.com, yipeng1.wang@intel.com, sameh.gobriel@intel.com, 
 bruce.richardson@intel.com, pablo.de.lara.guarch@intel.com,
 stephen@networkplumber.org,
 Pallantla Poornima <pallantlax.poornima@intel.com>, stable@dpdk.org
Date: Thu, 14 Feb 2019 12:57:42 +0000
Message-Id: <1550149062-14300-1-git-send-email-pallantlax.poornima@intel.com>
X-Mailer: git-send-email 1.7.0.7
In-Reply-To: <y>
References: <y>
Subject: [dpdk-stable] [PATCH v2] hash: fix sprintf with snprintf
X-BeenThere: stable@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches for DPDK stable branches <stable.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/stable>,
 <mailto:stable-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/stable/>
List-Post: <mailto:stable@dpdk.org>
List-Help: <mailto:stable-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/stable>,
 <mailto:stable-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Thu, 14 Feb 2019 12:58:25 -0000

sprintf function is not secure as it doesn't check the length of string.
More secure function snprintf is used.

Fixes: 473d1bebce ("hash: allow to store data in hash table")
Cc: stable@dpdk.org

Signed-off-by: Pallantla Poornima <pallantlax.poornima@intel.com>
---
v2: Addressed review comment to correct the format specifier of 
hastest_key_lens.
---

 test/test/test_hash_perf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/test/test/test_hash_perf.c b/test/test/test_hash_perf.c
index 525211180..5648fce02 100644
--- a/test/test/test_hash_perf.c
+++ b/test/test/test_hash_perf.c
@@ -85,9 +85,11 @@ create_table(unsigned int with_data, unsigned int table_index,
 
 	if (with_data)
 		/* Table will store 8-byte data */
-		sprintf(name, "test_hash%d_data", hashtest_key_lens[table_index]);
+		snprintf(name, sizeof(name), "test_hash%u_data",
+				hashtest_key_lens[table_index]);
 	else
-		sprintf(name, "test_hash%d", hashtest_key_lens[table_index]);
+		snprintf(name, sizeof(name), "test_hash%u",
+				hashtest_key_lens[table_index]);
 
 
 	if (with_locks)
-- 
2.17.2