Skip to contentSkip to conversation

Removing deprecated strncpy()

PATCH In review Kevin Paul Reddy Janagari 2 participants 3 messages Apr 10, 2025 – Apr 11, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Removing deprecated strncpy()

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

---
 net/tipc/link.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/tipc/link.c +1 -1
index 50c2e0846ea4..4859b3ccc094 100644
@@ -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)) {
Signature · 1 line
2.39.5
#1 lore raw
Quoted 1 line

which isn't really convenient for short strings as it may cause performce issues

Typo: /performce/performance
Also please append net-next to [PATCH] in your email subject.

Quoted 15 lines

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

Compile Tested

---
net/tipc/link.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
net/tipc/link.c index 50c2e0846ea4..4859b3ccc094 renamed from net/tipc/link.c +0 -0

100644

net/tipc/link.c static int tipc_link_proto_rcv(struct tipc_link *l, struct · line 2231

Quoted 6 lines
net/tipc/link.c +1 -1
@@ -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);

Could you please do the same replacement in function tipc_node_get_linkname() (node.c) ?

Quoted 7 lines
net/tipc/link.c +0 -0
 		/* 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