[dpdk-dev] [PATCH] examples/vhost_scsi: replace strncpy with strlcpy

Pattan, Reshma reshma.pattan at intel.com
Wed May 9 18:38:01 CEST 2018


Hi Bruce,

> -----Original Message-----
> From: Richardson, Bruce
> Sent: Wednesday, May 9, 2018 2:37 PM
> To: Pattan, Reshma <reshma.pattan at intel.com>
> Cc: dev at dpdk.org; stable at dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] examples/vhost_scsi: replace strncpy with
> strlcpy
> 
> 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 at dpdk.org
> >
> > Signed-off-by: Reshma Pattan <reshma.pattan at intel.com>
> > ---
> > -			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(...).
> 
If I take below piece of code as example ,  the application is trying to copy 
below strings to bare array which has no size defined to it. 
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 pass 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


More information about the dev mailing list