From patchwork Wed Nov 11 09:08:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jiang, Cheng1" X-Patchwork-Id: 83999 X-Patchwork-Delegate: maxime.coquelin@redhat.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 0F1A7A09D2; Wed, 11 Nov 2020 10:17:09 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D3EF5F90; Wed, 11 Nov 2020 10:17:06 +0100 (CET) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id 09F2DDED for ; Wed, 11 Nov 2020 10:17:04 +0100 (CET) IronPort-SDR: hDkci4FrOYEgk7FozffJ0bSvdaCXx/cFvWr+Pgfv/eNJg0FjWeil+uC28x4SRhk2lEcXqA8kif 6d1WYH51nuPg== X-IronPort-AV: E=McAfee;i="6000,8403,9801"; a="149393815" X-IronPort-AV: E=Sophos;i="5.77,469,1596524400"; d="scan'208";a="149393815" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2020 01:16:58 -0800 IronPort-SDR: UT13kjU0Svpz5jJCPdUkvL/wYyyzq6H3igr6eb+6aXD/afEKML7bqmg4efOA2NGn5U6PLn/p0R 2PreXYqRD/tA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,469,1596524400"; d="scan'208";a="356560312" Received: from dpdk_jiangcheng.sh.intel.com ([10.67.119.112]) by fmsmga004.fm.intel.com with ESMTP; 11 Nov 2020 01:16:56 -0800 From: Cheng Jiang To: maxime.coquelin@redhat.com, chenbo.xia@intel.com Cc: dev@dpdk.org, patrick.fu@intel.com, YvonneX.Yang@intel.com, Cheng Jiang Date: Wed, 11 Nov 2020 09:08:06 +0000 Message-Id: <20201111090806.43478-1-Cheng1.jiang@intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201106032343.9099-1-Cheng1.jiang@intel.com> References: <20201106032343.9099-1-Cheng1.jiang@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2] examples/vhost: fix string split error handling issue 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" Add checking return value of string split function to fix the coverity issue. Fixes: 3a04ecb21420 ("examples/vhost: add async vhost args parsing") Coverity issue: 363739 Signed-off-by: Cheng Jiang Reviewed-by: Maxime Coquelin --- v2: checked args_nr explicitly examples/vhost/ioat.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) -- 2.29.2 diff --git a/examples/vhost/ioat.c b/examples/vhost/ioat.c index b2c74f6537..720c0b0b81 100644 --- a/examples/vhost/ioat.c +++ b/examples/vhost/ioat.c @@ -36,7 +36,7 @@ open_ioat(const char *value) int ret = 0; uint16_t i = 0; char *dma_arg[MAX_VHOST_DEVICE]; - uint8_t args_nr; + int args_nr; while (isblank(*addrs)) addrs++; @@ -54,9 +54,18 @@ open_ioat(const char *value) } args_nr = rte_strsplit(substr, strlen(substr), dma_arg, MAX_VHOST_DEVICE, ','); - do { + if (args_nr <= 0) { + ret = -1; + goto out; + } + while (i < args_nr) { char *arg_temp = dma_arg[i]; - rte_strsplit(arg_temp, strlen(arg_temp), ptrs, 2, '@'); + uint8_t sub_nr; + sub_nr = rte_strsplit(arg_temp, strlen(arg_temp), ptrs, 2, '@'); + if (sub_nr != 2) { + ret = -1; + goto out; + } start = strstr(ptrs[0], "txd"); if (start == NULL) { @@ -105,7 +114,7 @@ open_ioat(const char *value) dma_info->nr++; i++; - } while (i < args_nr); + } out: free(input); return ret;