From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 9AD561B6ED; Wed, 9 May 2018 18:38:05 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 May 2018 09:38:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,382,1520924400"; d="scan'208";a="53766654" Received: from irsmsx104.ger.corp.intel.com ([163.33.3.159]) by fmsmga001.fm.intel.com with ESMTP; 09 May 2018 09:38:02 -0700 Received: from irsmsx110.ger.corp.intel.com ([169.254.15.125]) by IRSMSX104.ger.corp.intel.com ([169.254.5.96]) with mapi id 14.03.0319.002; Wed, 9 May 2018 17:38:01 +0100 From: "Pattan, Reshma" To: "Richardson, Bruce" CC: "dev@dpdk.org" , "stable@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH] examples/vhost_scsi: replace strncpy with strlcpy Thread-Index: AQHT54ndqpFIqMRkCEyovwTc3hgjbaQnVeiAgAA38vA= Date: Wed, 9 May 2018 16:38:01 +0000 Message-ID: <3AEA2BF9852C6F48A459DA490692831F2A2EDE55@irsmsx110.ger.corp.intel.com> References: <1525865729-16086-1-git-send-email-reshma.pattan@intel.com> <1525865729-16086-3-git-send-email-reshma.pattan@intel.com> <20180509133729.GB25048@bricha3-MOBL.ger.corp.intel.com> In-Reply-To: <20180509133729.GB25048@bricha3-MOBL.ger.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.180] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] examples/vhost_scsi: replace strncpy with strlcpy 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, 09 May 2018 16:38:06 -0000 Hi Bruce, > -----Original Message----- > From: Richardson, Bruce > Sent: Wednesday, May 9, 2018 2:37 PM > To: Pattan, Reshma > Cc: dev@dpdk.org; stable@dpdk.org > Subject: Re: [dpdk-dev] [PATCH] examples/vhost_scsi: replace strncpy with > strlcpy >=20 > On Wed, May 09, 2018 at 12:35:29PM +0100, Reshma Pattan wrote: > > Use strlcpy instead of strncpy. > > > > Fixes: db75c7af19 ("examples/vhost_scsi: introduce a new sample app") > > CC: stable@dpdk.org > > > > Signed-off-by: Reshma Pattan > > --- > > - strncpy((char *)vpage->params, bdev->name, 32); > > + strlcpy((char *)vpage->params, bdev->name, 32); > > - strncpy((char *)desig->desig, "INTEL", 8); > > + strlcpy((char *)desig->desig, "INTEL", 8); > > vhost_strcpy_pad((char *)&desig->desig[8], > > bdev->product_name, 16, ' '); > > - strncpy((char *)&desig->desig[24], bdev->name, 32); > > + strlcpy((char *)&desig->desig[24], bdev->name, 32); > > > > > > -- > Can the magic numbers "32", "8", "4" be replaced with non-magic values, e= .g. > sizeof(...). >=20 If I take below piece of code as example , the application is trying to co= py=20 below strings to bare array which has no size defined to it.=20 Neither there are any variable like brand name or device name available in= desig object which of type `struct scsi_desig_desc`, which I can use to p= ass on to sizeof() for using it for strlcpy. So not sure how to do address= the comment of using sizeof(). Any suggestions? strlcpy((char *)desig->desig, "INTEL", 8); strlcpy((char *)&desig->desig[24], bdev->name, 32); /* designation descriptor */ struct scsi_desig_desc { uint8_t code_set>*******: 4; uint8_t protocol_id>****: 4; uint8_t type>***>*******: 4; uint8_t association>****: 2; uint8_t reserved0>******: 1; uint8_t piv>****>*******: 1; uint8_t reserved1; uint8_t>len; uint8_t desig[]; }; Thanks, Reshma