[PATCH] Removing deprecated strncpy()

Kevin Paul Reddy Janagari posted 1 patch 10 months ago
There is a newer version of this series
net/tipc/link.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] Removing deprecated strncpy()
Posted by Kevin Paul Reddy Janagari 10 months ago
This patch suggests the replacement of strncpy with strscpy
as per Documentation/process/deprecated.
The strncpy() fails to guarntee NULL termination,
The function adds zero pads which isn't really convenient for short strings
as it may cause performce issues

strscpy() is a preffered replacement because
it overcomes the limitations of strncpy mentioned above

Compile Tested
Signed-off-by: Kevin Paul Reddy Janagari <kevinpaul468@gmail.com>
---
 net/tipc/link.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/tipc/link.c b/net/tipc/link.c
index 50c2e0846ea4..4859b3ccc094 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -2227,7 +2227,7 @@ static int tipc_link_proto_rcv(struct tipc_link *l, struct sk_buff *skb,
 			break;
 		if (msg_data_sz(hdr) < TIPC_MAX_IF_NAME)
 			break;
-		strncpy(if_name, data, TIPC_MAX_IF_NAME);
+		strscpy(if_name, data, TIPC_MAX_IF_NAME);
 
 		/* Update own tolerance if peer indicates a non-zero value */
 		if (tipc_in_range(peers_tol, TIPC_MIN_LINK_TOL, TIPC_MAX_LINK_TOL)) {
-- 
2.39.5