From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 8FA771B1B8 for ; Thu, 5 Oct 2017 15:01:16 +0200 (CEST) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP; 05 Oct 2017 06:01:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,481,1500966000"; d="scan'208";a="159190426" Received: from bricha3-mobl3.ger.corp.intel.com ([10.237.221.37]) by fmsmga005.fm.intel.com with SMTP; 05 Oct 2017 06:01:13 -0700 Received: by (sSMTP sendmail emulation); Thu, 05 Oct 2017 14:01:12 +0100 Date: Thu, 5 Oct 2017 14:01:12 +0100 From: Bruce Richardson To: Maxime Coquelin Cc: "Piasecki, JacekX" , "Jastrzebski, MichalX K" , "yliu@fridaylinux.org" , "dev@dpdk.org" , "Jain, Deepak K" , "Liu, Changpeng" Message-ID: <20171005130112.GB12160@bricha3-MOBL3.ger.corp.intel.com> References: <20170922130734.7256-1-michalx.k.jastrzebski@intel.com> <60ABE07DBB3A454EB7FAD707B4BB158213C40F16@IRSMSX109.ger.corp.intel.com> <0a469856-29c8-a79e-bb6a-ad21dfbccaf4@redhat.com> <8B71977F507A4143BF605D4D8BA8F23C0114CD14@HASMSX106.ger.corp.intel.com> <52f9f89c-dcf0-a3cb-166c-76ec2c83ddc5@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <52f9f89c-dcf0-a3cb-166c-76ec2c83ddc5@redhat.com> Organization: Intel Research and Development Ireland Ltd. User-Agent: Mutt/1.8.3 (2017-05-23) Subject: Re: [dpdk-dev] [PATCH] 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: Thu, 05 Oct 2017 13:01:17 -0000 On Thu, Oct 05, 2017 at 02:42:24PM +0200, Maxime Coquelin wrote: > > > On 10/05/2017 02:35 PM, Piasecki, JacekX wrote: > > -----Original Message----- > > From: Maxime Coquelin [mailto:maxime.coquelin@redhat.com] > > Sent: Monday, 2 October, 2017 17:07 > > To: Jastrzebski, MichalX K ; yliu@fridaylinux.org > > Cc: dev@dpdk.org; Jain, Deepak K ; Piasecki, JacekX ; Liu, Changpeng ; stable@dpdk.org > > Subject: Re: [dpdk-dev] [PATCH] examples/vhost_scsi: fix buffer not terminated > > > > > > > > On 10/02/2017 03:50 PM, Jastrzebski, MichalX K wrote: > > > > -----Original Message----- > > > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Michal > > > > Jastrzebski > > > > Sent: Friday, September 22, 2017 3:08 PM > > > > To: yliu@fridaylinux.org; maxime.coquelin@redhat.com > > > > Cc: dev@dpdk.org; Jain, Deepak K ; Piasecki, > > > > JacekX ; Liu, Changpeng > > > > ; stable@dpdk.org > > > > Subject: [dpdk-dev] [PATCH] examples/vhost_scsi: fix buffer not > > > > terminated > > > > > > > > From: Jacek Piasecki > > > > > > > > Fix size of buffer in strcpy. There was possible to get not > > > > terminated string after copy 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 > > > > --- > > > > examples/vhost_scsi/scsi.c | 3 ++- > > > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/examples/vhost_scsi/scsi.c b/examples/vhost_scsi/scsi.c > > > > index 54d3104..de9639a 100644 > > > > --- a/examples/vhost_scsi/scsi.c > > > > +++ b/examples/vhost_scsi/scsi.c > > > > @@ -307,7 +307,8 @@ > > > > strncpy((char *)inqdata->t10_vendor_id, "INTEL", 8); > > > > > > > > /* PRODUCT IDENTIFICATION */ > > > > - strncpy((char *)inqdata->product_id, bdev->product_name, > > > > 16); > > > > + strncpy((char *)inqdata->product_id, bdev->product_name, > > > > + ARRAY_SIZE(inqdata->product_id) - 1); > > > > Does it assume that product_id is memzero'ed before? > > IIUC strncpy manpage, it wouldn't protect against non-null terminated strings if it is not the case: > > > > Yes, I assumed that this area is zeroed before strncpy. Earlier there is a casting from *task to *inqdata (*task is zmalloced). > Ok. I think the assumption is dangerous. > > > To be sure that the destination area is clear I propose to add: > > memset(inqdata->product_id, 0, ARRAY_SIZE(inqdata->product_id)); > > before strncpy. Would that be OK? > > Or call strncpy with ARRAY_SIZE(inqdata->product_id) as max length, > and then do > inqdata->product_id[ARRAY_SIZE(inqdata->product_id) - 1] = '\0'; > > Regards, > Maxime > > Or use snprintf instead of strncpy, as we do in many places in DPDK. Still only one line of code, with nice null-termination, and truncation semantics. /Bruce