Thread (3 messages) 3 messages, 1 author, 2021-06-03
STALE1868d REVIEWED: 1 (0M)
Revisions (3)
  1. v1 [diff vs current]
  2. v1 current
  3. v2 [diff vs current]

[PATCH 2/2] libfc: Corrected the condition check and invalid argument passed

From: Javed Hasan <jhasan@marvell.com>
Date: 2021-06-03 09:57:52
Subsystem: fcoe subsystem (libfc, libfcoe, fcoe), scsi subsystem, the rest · Maintainers: Hannes Reinecke, "James E.J. Bottomley", "Martin K. Petersen", Linus Torvalds

 -In correct condition check was leading to data corruption
  and so the invalid argument.

Fixes: 8fd9efca86d0 ("scsi: libfc: Work around -Warray-bounds warning")
Signed-off-by: Javed Hasan <jhasan@marvell.com>
Reviewed-by: Himanshu Madhani <redacted>
---
 drivers/scsi/libfc/fc_encode.h | 8 +++++---
 1 file 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);
 }
 
 /**
-- 
2.26.2
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help