summaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libfc
diff options
context:
space:
mode:
authorJaved Hasan <jhasan@marvell.com>2021-06-03 03:14:04 -0700
committerMartin K. Petersen <martin.petersen@oracle.com>2021-06-09 23:55:38 -0400
commit8f70328c068f9f5c5db82848724cb276f657b9cd (patch)
treef731f01cb4919e718c5b3b195b4e41b8626a4112 /drivers/scsi/libfc
parent40445fd2c9fa427297acdfcc2c573ff10493f209 (diff)
downloadlinux-8f70328c068f9f5c5db82848724cb276f657b9cd.tar.gz
linux-8f70328c068f9f5c5db82848724cb276f657b9cd.tar.bz2
linux-8f70328c068f9f5c5db82848724cb276f657b9cd.zip
scsi: libfc: Correct the condition check and invalid argument passed
Incorrect condition check was leading to data corruption. Link: https://lore.kernel.org/r/20210603101404.7841-3-jhasan@marvell.com Fixes: 8fd9efca86d0 ("scsi: libfc: Work around -Warray-bounds warning") CC: stable@vger.kernel.org Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com> Signed-off-by: Javed Hasan <jhasan@marvell.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Diffstat (limited to 'drivers/scsi/libfc')
-rw-r--r--drivers/scsi/libfc/fc_encode.h8
1 files changed, 5 insertions, 3 deletions
diff --git a/drivers/scsi/libfc/fc_encode.h b/drivers/scsi/libfc/fc_encode.h
index 602c97a651bc..9ea4ceadb559 100644
--- a/drivers/scsi/libfc/fc_encode.h
+++ b/drivers/scsi/libfc/fc_encode.h
@@ -166,9 +166,11 @@ static inline int fc_ct_ns_fill(struct fc_lport *lport,
static inline void fc_ct_ms_fill_attr(struct fc_fdmi_attr_entry *entry,
const char *in, size_t len)
{
- int copied = strscpy(entry->value, in, len);
- if (copied > 0)
- memset(entry->value, copied, len - copied);
+ int copied;
+
+ copied = strscpy((char *)&entry->value, in, len);
+ if (copied > 0 && (copied + 1) < len)
+ memset((entry->value + copied + 1), 0, len - copied - 1);
}
/**