[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20251031095348.24775-1-i.shihao.999@gmail.com>
Date: Fri, 31 Oct 2025 15:23:48 +0530
From: Shi Hao <i.shihao.999@...il.com>
To: martin.petersen@...cle.com
Cc: linux-scsi@...r.kernel.org,
target-devel@...r.kernel.org,
linux-kernel@...r.kernel.org,
i.shihao.999@...il.com
Subject: [PATCH] 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.
Signed-off-by: Shi Hao <i.shihao.999@...il.com>
---
drivers/target/target_core_transport.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 0a76bdfe5528..9c255ed21789 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -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
Powered by blists - more mailing lists