Skip to contentSkip to conversation

scsi: target: replace strncpy() with strscpy()

PATCH New Shi Hao 1 participant 1 message Oct 31, 2025

Subsystems (2)
lore
Share & tools
lore

Shi Hao

author
#0 lore raw

PATCH 1/1 scsi: target: replace strncpy() with strscpy()

Replace strncpy function calls to more reliable function like strscpy for safer null termination.

Earlier code had some strncpy functions still in use which could be replaced with strscpy() since it always NULL terminates the destina -tion buffer also it does not waste cycles padding with zeros unlike strncpy(). In regard to this convert strncpy to strscpy to prevent accidental buffer overreads and ensure null termination of destination buffer.

No functional changes intended.

---
 drivers/target/target_core_transport.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/target/target_core_transport.c +4 -4
index 0a76bdfe5528..9c255ed21789 100644
@@ -1112,7 +1112,7 @@ void transport_dump_vpd_proto_id(
 	}
 
 	if (p_buf)
-		strncpy(p_buf, buf, p_buf_len);
+		strscpy(p_buf, buf, p_buf_len);
 	else
 		pr_debug("%s", buf);
 }
@@ -1162,7 +1162,7 @@ int transport_dump_vpd_assoc(
 	}
 
 	if (p_buf)
-		strncpy(p_buf, buf, p_buf_len);
+		strscpy(p_buf, buf, p_buf_len);
 	else
 		pr_debug("%s", buf);
 
@@ -1222,7 +1222,7 @@ int transport_dump_vpd_ident_type(
 	if (p_buf) {
 		if (p_buf_len < strlen(buf)+1)
 			return -EINVAL;
-		strncpy(p_buf, buf, p_buf_len);
+		strscpy(p_buf, buf, p_buf_len);
 	} else {
 		pr_debug("%s", buf);
 	}
@@ -1276,7 +1276,7 @@ int transport_dump_vpd_ident(
 	}
 
 	if (p_buf)
-		strncpy(p_buf, buf, p_buf_len);
+		strscpy(p_buf, buf, p_buf_len);
 	else
 		pr_debug("%s", buf);
 

--
2.51.0