From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8CFBBA0548; Tue, 27 Apr 2021 05:27:56 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6A84E40143; Tue, 27 Apr 2021 05:27:56 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mails.dpdk.org (Postfix) with ESMTP id 0B4474003E for ; Tue, 27 Apr 2021 05:27:54 +0200 (CEST) IronPort-SDR: t/59BlnThzpPktTpTxHxy+XvkSx4SWDBE+lRbrutciL+2XP8NXM+bNWolA35WlxFlQSkMH+vfy e39Jov4kyUog== X-IronPort-AV: E=McAfee;i="6200,9189,9966"; a="175924271" X-IronPort-AV: E=Sophos;i="5.82,254,1613462400"; d="scan'208";a="175924271" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2021 20:27:53 -0700 IronPort-SDR: vuNzjTe96IoC9nutiS1Kp2PZuy5gU5H1i9EF/+NOC3JrA9kZGp0930cI23HnJjSGTeD2S6DMWI U/Yya3TOy/IA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,254,1613462400"; d="scan'208";a="457447253" Received: from dpdk_jiangcheng.sh.intel.com ([10.67.119.112]) by fmsmga002.fm.intel.com with ESMTP; 26 Apr 2021 20:27:52 -0700 From: Cheng Jiang To: maxime.coquelin@redhat.com, chenbo.xia@intel.com Cc: dev@dpdk.org, david.marchand@redhat.com, Cheng Jiang Date: Tue, 27 Apr 2021 03:14:01 +0000 Message-Id: <20210427031401.4369-1-Cheng1.jiang@intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210419054426.26812-1-Cheng1.jiang@intel.com> References: <20210419054426.26812-1-Cheng1.jiang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2] examples/vhost: fix potential overflow in args process X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" Change the way passing args to fix potential overflow in args process. Coverity issue: 363741 Fixes: 965b06f0358 ("examples/vhost: enhance getopt_long usage") Signed-off-by: Cheng Jiang --- v2: * Change the way passing args * Change git log examples/vhost/main.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/examples/vhost/main.c b/examples/vhost/main.c index 119ba7e01..3e2e9a45c 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -55,9 +55,6 @@ #define INVALID_PORT_ID 0xFF -/* Maximum long option length for option parsing. */ -#define MAX_LONG_OPT_SZ 64 - /* mask of enabled ports */ static uint32_t enabled_port_mask = 0; @@ -97,7 +94,7 @@ static int builtin_net_driver; static int async_vhost_driver; -static char dma_type[MAX_LONG_OPT_SZ]; +static char *dma_type; /* Specify timeout (in useconds) between retries on RX. */ static uint32_t burst_rx_delay_time = BURST_RX_WAIT_US; @@ -201,7 +198,7 @@ struct vhost_bufftable *vhost_txbuff[RTE_MAX_LCORE * MAX_VHOST_DEVICE]; static inline int open_dma(const char *value) { - if (strncmp(dma_type, "ioat", 4) == 0) + if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0) return open_ioat(value); return -1; @@ -669,7 +666,7 @@ us_vhost_parse_args(int argc, char **argv) break; case OPT_DMA_TYPE_NUM: - strcpy(dma_type, optarg); + dma_type = optarg; break; case OPT_DMAS_NUM: @@ -1472,7 +1469,7 @@ new_device(int vid) struct rte_vhost_async_features f; struct rte_vhost_async_channel_ops channel_ops; - if (strncmp(dma_type, "ioat", 4) == 0) { + if (dma_type != NULL && strncmp(dma_type, "ioat", 4) == 0) { channel_ops.transfer_data = ioat_transfer_data_cb; channel_ops.check_completed_copies = ioat_check_completed_copies_cb; -- 2.29.2