From patchwork Wed Feb 19 12:40:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ferruh Yigit X-Patchwork-Id: 65902 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id A8499A0555; Wed, 19 Feb 2020 13:40:10 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 18FBF1BF81; Wed, 19 Feb 2020 13:40:10 +0100 (CET) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id EDFCD25B3 for ; Wed, 19 Feb 2020 13:40:08 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Feb 2020 04:40:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,459,1574150400"; d="scan'208";a="235881270" Received: from silpixa00399752.ir.intel.com (HELO silpixa00399752.ger.corp.intel.com) ([10.237.222.180]) by orsmga003.jf.intel.com with ESMTP; 19 Feb 2020 04:40:05 -0800 From: Ferruh Yigit To: Wenzhuo Lu , Jingjing Wu , Bernard Iremonger , Herakliusz Lipiec , Hariprasad Govindharajan , Anatoly Burakov Cc: dev@dpdk.org, Ferruh Yigit Date: Wed, 19 Feb 2020 12:40:03 +0000 Message-Id: <20200219124003.1025267-1-ferruh.yigit@intel.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH] app/testpmd: guarantee that array access is in range 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" Coverity complains about out of bound access, which is a false positive. The return value of the 'parse_port_list()' can't be bigger than 'maxsize' because of the logic in the function. ('value >= (int)maxsize' check and 'marked[]' usage.) But this is not explicitly clear, causing coverity warning and same question can be rise by reviews later. Adding a redundant check to highlight the access is in range, this is done by replacing existing redundant check. This is also good to protect against out out bound access in case 'parse_port_list()' behaviour changes later unexpectedly. Coverity issue: 354229 Fixes: 2df00d562d20 ("app/testpmd: add --portlist option") Signed-off-by: Ferruh Yigit Reviewed-by: Herakliusz Lipiec Acked-by: Bernard Iremonger --- app/test-pmd/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 9d9520223..d93941f03 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -2703,7 +2703,7 @@ parse_fwd_portlist(const char *portlist) * and thereby calculate the total number of * valid ports */ - for (i = 0; i < portcount && valid_port_count < portcount; i++) { + for (i = 0; i < portcount && i < RTE_DIM(portindex); i++) { if (rte_eth_dev_is_valid_port(portindex[i])) { portindex[valid_port_count] = portindex[i]; valid_port_count++;