From patchwork Mon Feb 18 10:50:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Poornima, PallantlaX" X-Patchwork-Id: 50345 X-Patchwork-Delegate: thomas@monjalon.net 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 C8A155B16; Mon, 18 Feb 2019 11:50:53 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 095225323; Mon, 18 Feb 2019 11:50:51 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Feb 2019 02:50:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,384,1544515200"; d="scan'208";a="125292231" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga008.fm.intel.com with ESMTP; 18 Feb 2019 02:50:49 -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 x1IAon3a026170; Mon, 18 Feb 2019 10:50:49 GMT Received: from wgcvswdev001.ir.intel.com (localhost [127.0.0.1]) by wgcvswdev001.ir.intel.com with ESMTP id x1IAoCRO000882; Mon, 18 Feb 2019 10:50:12 GMT Received: (from ppoornix@localhost) by wgcvswdev001.ir.intel.com with ? id x1IAoCaE000877; Mon, 18 Feb 2019 10:50:12 GMT From: Pallantla Poornima To: dev@dpdk.org Cc: reshma.pattan@intel.com, amr.mokhtar@intel.com, ferruh.yigit@intel.com, Pallantla Poornima , stable@dpdk.org Date: Mon, 18 Feb 2019 10:50:10 +0000 Message-Id: <1550487010-730-1-git-send-email-pallantlax.poornima@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2] app/testbbdev: fix sprintf with snprintf or strlcpy 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" sprintf function is not secure as it doesn't check the length of string. More secure function snprintf and strlcpy is used. Fixes: f714a18885 ("app/testbbdev: add test application for bbdev") Cc: stable@dpdk.org Signed-off-by: Pallantla Poornima --- v2: Used strlcpy instead of snprintf as suggested. --- app/test-bbdev/test_bbdev.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/test-bbdev/test_bbdev.c b/app/test-bbdev/test_bbdev.c index a914817bc..137c74cde 100644 --- a/app/test-bbdev/test_bbdev.c +++ b/app/test-bbdev/test_bbdev.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include "main.h" @@ -788,14 +790,14 @@ test_bbdev_driver_init(void) /* Initialize the maximum amount of devices */ do { - sprintf(name_tmp, "%s%i", "name_", num_devs); + snprintf(name_tmp, sizeof(name_tmp), "%s%i", "name_", num_devs); dev2 = rte_bbdev_allocate(name_tmp); TEST_ASSERT(dev2 != NULL, "Failed to initialize bbdev driver"); ++num_devs; } while (num_devs < (RTE_BBDEV_MAX_DEVS - 1)); - sprintf(name_tmp, "%s%i", "name_", num_devs); + snprintf(name_tmp, sizeof(name_tmp), "%s%i", "name_", num_devs); dev2 = rte_bbdev_allocate(name_tmp); TEST_ASSERT(dev2 == NULL, "Failed to initialize bbdev driver number %d " "more drivers than RTE_BBDEV_MAX_DEVS: %d ", num_devs, @@ -804,7 +806,7 @@ test_bbdev_driver_init(void) num_devs--; while (num_devs >= num_devs_tmp) { - sprintf(name_tmp, "%s%i", "name_", num_devs); + snprintf(name_tmp, sizeof(name_tmp), "%s%i", "name_", num_devs); dev2 = rte_bbdev_get_named_dev(name_tmp); TEST_ASSERT_SUCCESS(rte_bbdev_release(dev2), "Failed to uninitialize bbdev driver %s ", @@ -825,7 +827,7 @@ test_bbdev_driver_init(void) TEST_ASSERT_FAIL(rte_bbdev_release(NULL), "Failed to uninitialize bbdev driver with NULL bbdev"); - sprintf(name_tmp, "%s", "invalid_name"); + strlcpy(name_tmp, "invalid_name", sizeof(name_tmp)); dev2 = rte_bbdev_get_named_dev(name_tmp); TEST_ASSERT_FAIL(rte_bbdev_release(dev2), "Failed to uninitialize bbdev driver with invalid name");