From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id F34601B7D9; Wed, 25 Oct 2017 12:09:06 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Oct 2017 03:09:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,431,1503385200"; d="scan'208";a="1209847484" Received: from gklab-246-073.igk.intel.com (HELO Sent) ([10.217.246.73]) by fmsmga001.fm.intel.com with SMTP; 25 Oct 2017 03:09:02 -0700 Received: by Sent (sSMTP sendmail emulation); Wed, 25 Oct 2017 12:07:52 +0200 From: Jacek Piasecki To: dev@dpdk.org Cc: maxime.coquelin@redhat.com, thomas@monjalon.net, yliu@fridaylinux.org, Jacek Piasecki , changpeng.liu@intel.com, stable@dpdk.org Date: Wed, 25 Oct 2017 12:07:18 +0200 Message-Id: <1508926038-12821-1-git-send-email-jacekx.piasecki@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1507808061-37679-1-git-send-email-jacekx.piasecki@intel.com> References: <1507808061-37679-1-git-send-email-jacekx.piasecki@intel.com> Subject: [dpdk-dev] [PATCH v4] examples/vhost_scsi: fix buffer not terminated 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: Wed, 25 Oct 2017 10:09:08 -0000 Use snprintf instead strncpy to get safe null string termination. There was possible to get not terminated string after strncpy operation. Coverity issue: 158631 Fixes: db75c7af19bb ("examples/vhost_scsi: introduce a new sample app") Cc: changpeng.liu@intel.com Cc: stable@dpdk.org Signed-off-by: Jacek Piasecki Acked-by: Maxime Coquelin --- v4: RTE_DIM instead ARRAY_SIZE v3: checkpatch fix v2: snprintf instead strncpy --- examples/vhost_scsi/scsi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/vhost_scsi/scsi.c b/examples/vhost_scsi/scsi.c index 54d3104..fd430ec 100644 --- a/examples/vhost_scsi/scsi.c +++ b/examples/vhost_scsi/scsi.c @@ -307,7 +307,9 @@ vhost_bdev_scsi_inquiry_command(struct vhost_block_dev *bdev, strncpy((char *)inqdata->t10_vendor_id, "INTEL", 8); /* PRODUCT IDENTIFICATION */ - strncpy((char *)inqdata->product_id, bdev->product_name, 16); + snprintf((char *)inqdata->product_id, + RTE_DIM(inqdata->product_id), "%s", + bdev->product_name); /* PRODUCT REVISION LEVEL */ strncpy((char *)inqdata->product_rev, "0001", 4); -- 2.7.4