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

Message ID 1525953944-11339-1-git-send-email-reshma.pattan@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Pattan, Reshma May 10, 2018, 12:05 p.m. UTC
  Use strlcpy instead of strncpy.

Fixes: db75c7af19 ("examples/vhost_scsi: introduce a new sample app")
CC: stable@dpdk.org

Signed-off-by: Reshma Pattan <reshma.pattan@intel.com>
---
v2: replace magic numbers with sizeof() wherever possible.
---
 examples/vhost_scsi/scsi.c      | 14 +++++++++-----
 examples/vhost_scsi/scsi_spec.h |  2 +-
 2 files changed, 10 insertions(+), 6 deletions(-)
  

Comments

Bruce Richardson May 10, 2018, 1:31 p.m. UTC | #1
On Thu, May 10, 2018 at 01:05:44PM +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 <reshma.pattan@intel.com>
> ---
> v2: replace magic numbers with sizeof() wherever possible.
> ---
>  examples/vhost_scsi/scsi.c      | 14 +++++++++-----
>  examples/vhost_scsi/scsi_spec.h |  2 +-
>  2 files changed, 10 insertions(+), 6 deletions(-)
> 
Looks better now, thanks.
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  
Thomas Monjalon May 13, 2018, 9:50 p.m. UTC | #2
10/05/2018 15:31, Bruce Richardson:
> On Thu, May 10, 2018 at 01:05:44PM +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 <reshma.pattan@intel.com>
> > ---
> > v2: replace magic numbers with sizeof() wherever possible.
> > ---
> >  examples/vhost_scsi/scsi.c      | 14 +++++++++-----
> >  examples/vhost_scsi/scsi_spec.h |  2 +-
> >  2 files changed, 10 insertions(+), 6 deletions(-)
> > 
> Looks better now, thanks.
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>

Applied, thanks
  

Patch

diff --git a/examples/vhost_scsi/scsi.c b/examples/vhost_scsi/scsi.c
index 2a034bb9b..0c2fa3e6a 100644
--- a/examples/vhost_scsi/scsi.c
+++ b/examples/vhost_scsi/scsi.c
@@ -20,6 +20,7 @@ 
 #include <rte_log.h>
 #include <rte_malloc.h>
 #include <rte_byteorder.h>
+#include <rte_string_fns.h>
 
 #include "vhost_scsi.h"
 #include "scsi_spec.h"
@@ -181,7 +182,8 @@  vhost_bdev_scsi_inquiry_command(struct vhost_block_dev *bdev,
 			break;
 		case SPC_VPD_UNIT_SERIAL_NUMBER:
 			hlen = 4;
-			strncpy((char *)vpage->params, bdev->name, 32);
+			strlcpy((char *)vpage->params, bdev->name,
+					sizeof(vpage->params));
 			vpage->alloc_len = rte_cpu_to_be_16(32);
 			break;
 		case SPC_VPD_DEVICE_IDENTIFICATION:
@@ -215,10 +217,10 @@  vhost_bdev_scsi_inquiry_command(struct vhost_block_dev *bdev,
 			desig->piv = 1;
 			desig->reserved1 = 0;
 			desig->len = 8 + 16 + 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);
 			len += sizeof(struct scsi_desig_desc) + 8 + 16 + 32;
 
 			buf += sizeof(struct scsi_desig_desc) + desig->len;
@@ -275,7 +277,8 @@  vhost_bdev_scsi_inquiry_command(struct vhost_block_dev *bdev,
 		inqdata->flags3 = 0x2;
 
 		/* T10 VENDOR IDENTIFICATION */
-		strncpy((char *)inqdata->t10_vendor_id, "INTEL", 8);
+		strlcpy((char *)inqdata->t10_vendor_id, "INTEL",
+			sizeof(inqdata->t10_vendor_id));
 
 		/* PRODUCT IDENTIFICATION */
 		snprintf((char *)inqdata->product_id,
@@ -283,7 +286,8 @@  vhost_bdev_scsi_inquiry_command(struct vhost_block_dev *bdev,
 				bdev->product_name);
 
 		/* PRODUCT REVISION LEVEL */
-		strncpy((char *)inqdata->product_rev, "0001", 4);
+		strlcpy((char *)inqdata->product_rev, "0001",
+			sizeof(inqdata->product_rev));
 
 		/* Standard inquiry data ends here. Only populate
 		 * remaining fields if alloc_len indicates enough
diff --git a/examples/vhost_scsi/scsi_spec.h b/examples/vhost_scsi/scsi_spec.h
index 5c7a894bd..27be02688 100644
--- a/examples/vhost_scsi/scsi_spec.h
+++ b/examples/vhost_scsi/scsi_spec.h
@@ -367,7 +367,7 @@  struct scsi_vpd_page {
 	uint8_t peripheral;
 	uint8_t page_code;
 	uint16_t alloc_len;
-	uint8_t params[];
+	uint8_t params[32];
 };
 
 #define SCSI_VEXT_REF_CHK		0x01