Removing deprecated strncpy()
Subsystems (3)
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
@@ -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
Tung Quang Nguyen
maintainerQuoted 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 aboveCompile Tested
Signed-off-by Kevin Paul Reddy Janagari <[email protected]>---
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
-0100644
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, structsk_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
replacement of strncpy in ticp_node_get_linkname()
https://lore.kernel.org/all/[email protected]
Reguards
kevin