From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id AE1CA1B8FC; Fri, 8 Feb 2019 14:28:18 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Feb 2019 05:28:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,347,1544515200"; d="scan'208";a="120953871" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga007.fm.intel.com with ESMTP; 08 Feb 2019 05:28:16 -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 x18DSFuH019528; Fri, 8 Feb 2019 13:28:15 GMT Received: from wgcvswdev001.ir.intel.com (localhost [127.0.0.1]) by wgcvswdev001.ir.intel.com with ESMTP id x18DRe7J016026; Fri, 8 Feb 2019 13:27:40 GMT Received: (from ppoornix@localhost) by wgcvswdev001.ir.intel.com with œ id x18DReWg016022; Fri, 8 Feb 2019 13:27:40 GMT From: Pallantla Poornima To: dev@dpdk.org Cc: reshma.pattan@intel.com, ferruh.yigit@intel.com, Pallantla Poornima , stable@dpdk.org Date: Fri, 8 Feb 2019 13:27:37 +0000 Message-Id: <1549632457-15892-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] test: fix sprintf with snprintf 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: Fri, 08 Feb 2019 13:28:19 -0000 sprintf function is not secure as it doesn't check the length of string. More secure function snprintf is used. Fixes: 727909c592 ("app/test: introduce dynamic commands list") Cc: stable@dpdk.org Signed-off-by: Pallantla Poornima --- test/test/commands.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/test/commands.c b/test/test/commands.c index 94fbc310e..5aeb35498 100644 --- a/test/test/commands.c +++ b/test/test/commands.c @@ -367,6 +367,8 @@ int commands_init(void) struct test_command *t; char *commands, *ptr; int commands_len = 0; + int total_written = 0; + int count = 0; TAILQ_FOREACH(t, &commands_list, next) { commands_len += strlen(t->command) + 1; @@ -378,7 +380,10 @@ int commands_init(void) ptr = commands; TAILQ_FOREACH(t, &commands_list, next) { - ptr += sprintf(ptr, "%s#", t->command); + count = snprintf(ptr, commands_len - total_written - 1, "%s#", + t->command); + ptr += count; + total_written += count; } ptr--; ptr[0] = '\0'; -- 2.17.2