On Thu, 2018-11-29 at 02:01 +0100, David Disseldorp wrote: > - strncpy(&dev->t10_wwn.vendor[0], "LIO-ORG", 8); > + strncpy(&dev->t10_wwn.vendor[0], "LIO-ORG", INQUIRY_VENDOR_LEN); > + dev->t10_wwn.vendor[INQUIRY_VENDOR_LEN] = '\0';
This looks weird to me. Have you considered to use strlcpy() instead of strncpy() and explicit '\0'-termination? > strncpy(&dev->t10_wwn.model[0], > dev->transport->inquiry_prod, 16); > strncpy(&dev->t10_wwn.revision[0], > diff --git a/drivers/target/target_core_pscsi.c > b/drivers/target/target_core_pscsi.c > index 47d76c862014..ee65b5bb674c 100644 > --- a/drivers/target/target_core_pscsi.c > +++ b/drivers/target/target_core_pscsi.c > @@ -190,7 +190,9 @@ pscsi_set_inquiry_info(struct scsi_device *sdev, struct > t10_wwn *wwn) > /* > * Use sdev->inquiry from drivers/scsi/scsi_scan.c:scsi_alloc_sdev() > */ > - memcpy(&wwn->vendor[0], &buf[8], sizeof(wwn->vendor)); > + BUILD_BUG_ON(sizeof(wwn->vendor) != INQUIRY_VENDOR_LEN + 1); > + memcpy(&wwn->vendor[0], &buf[8], INQUIRY_VENDOR_LEN); > + wwn->vendor[INQUIRY_VENDOR_LEN] = '\0'; Have you considered to use snprintf(..., "%.*s", ...) instead of memcpy() followed by explicit '\0'-termination? I think that would result in code that is easier to read. strlcpy() can't be used here because it is not guaranteed that the input buffer is '\0'-terminated. Thanks, Bart.