tipc: Removing deprecated strncpy()
Subsystems (3)
PATCH 1/1 tipc: Removing deprecated strncpy()
This patch suggests the replacement of strncpy with strscpy
as per Documentation/process/deprecated.
The strncpy() fails to guarantee NULL termination,
The function adds zero pads which isn't really convenient for short strings as it may cause performance issues.
strscpy() is a preferred replacement because
it overcomes the limitations of strncpy mentioned above.
Compile Tested
--- net/tipc/link.c | 2 +- net/tipc/node.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/tipc/link.c +1 -1
@@ -2228,7 +2228,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 )) {
net/tipc/node.c +1 -1
@@ -1581,7 +1581,7 @@ int tipc_node_get_linkname(struct net *net, u32 bearer_id, u32 addr,tipc_node_read_lock (node); link = node->links[bearer_id].link;if (link) { -strncpy (linkname,tipc_link_name (link), len); +strscpy (linkname,tipc_link_name (link), len); err =0 ; }tipc_node_read_unlock (node);
Signature · 1 line
2.39.5
Tung Quang Nguyen
maintainerQuoted 45 lines
This patch suggests the replacement of strncpy with strscpy as per
Documentation/process/deprecated.
Thestrncpy()fails to guarantee NULL termination, The function adds zero pads which isn't really convenient for short strings as it may cause performance issues.
strscpy()is a preferred replacement because it overcomes the limitations of strncpy mentioned above.Compile Tested
Signed-off-by Kevin Paul Reddy Janagari <[email protected]>---
net/tipc/link.c| 2 +-net/tipc/node.c| 2 +-2 files changed, 2 insertions(+), 2 deletions(-)net/tipc/link.c index 18be6ff4c3db..3ee44d731700 renamed from net/tipc/link.c +0
-0100644
net/tipc/link.c +1
-1@@ -2228,7 +2228,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 );/* Update own tolerance if peer indicates a non-zero value */ if (tipc_in_range(peers_tol,
TIPC_MIN_LINK_TOL,TIPC_MAX_LINK_TOL)) { diff --gita/net/tipc/node.cb/net/tipc/node.cindexccf5e427f43e..cb43f2016a70100644net/tipc/node.c +1
-1@@ -1581,7 +1581,7 @@ int tipc_node_get_linkname(struct net *net, u32 bearer_id, u32 addr,tipc_node_read_lock (node); link = node->links[bearer_id].link;if (link) { -strncpy (linkname,tipc_link_name (link), len); +strscpy (linkname,tipc_link_name (link), len); err =0 ; }tipc_node_read_unlock(node);
Quoted 2 lines
--
2.39.5
Quoted 40 lines · Tung Quang Nguyen
Quoted 40 lines
This patch suggests the replacement of strncpy with strscpy as per
Documentation/process/deprecated.
Thestrncpy()fails to guarantee NULL termination, The function adds zero pads which isn't really convenient for short strings as it may cause performance issues.
strscpy()is a preferred replacement because it overcomes the limitations of strncpy mentioned above.Compile Tested
Signed-off-by Kevin Paul Reddy Janagari <[email protected]>---
net/tipc/link.c| 2 +-net/tipc/node.c| 2 +-2 files changed, 2 insertions(+), 2 deletions(-)net/tipc/link.c index 18be6ff4c3db..3ee44d731700 renamed from net/tipc/link.c +0
-0100644
net/tipc/link.c +1
-1@@ -2228,7 +2228,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 );/* Update own tolerance if peer indicates a non-zero value */ if (tipc_in_range(peers_tol,
TIPC_MIN_LINK_TOL,TIPC_MAX_LINK_TOL)) { diff --gita/net/tipc/node.cb/net/tipc/node.cindexccf5e427f43e..cb43f2016a70100644net/tipc/node.c +0
-0@@ -1581,7 +1581,7 @@ int tipc_node_get_linkname(struct net *net, u32 bearer_id, u32 addr,tipc_node_read_lock (node); link = node->links[bearer_id].link;if (link) {
Quoted 8 lines
Quoted 7 lines
net/tipc/node.c +1
-1-strncpy (linkname,tipc_link_name (link), len); +strscpy (linkname,tipc_link_name (link), len); err =0 ; }tipc_node_read_unlock(node);--
2.39.5Reviewed-and-tested-by Tung Nguyen <[email protected]>
Hi Tung,
Thanks for reviewing these patches,
but I think it's best not to use non-standard tags.
Quoted 45 lines
This patch suggests the replacement of strncpy with strscpy as per
Documentation/process/deprecated.
Thestrncpy()fails to guarantee NULL termination, The function adds zero pads which isn't really convenient for short strings as it may cause performance issues.
strscpy()is a preferred replacement because it overcomes the limitations of strncpy mentioned above.Compile Tested
Signed-off-by Kevin Paul Reddy Janagari <[email protected]>---
net/tipc/link.c| 2 +-net/tipc/node.c| 2 +-2 files changed, 2 insertions(+), 2 deletions(-)net/tipc/link.c index 18be6ff4c3db..3ee44d731700 renamed from net/tipc/link.c +0
-0100644
net/tipc/link.c +1
-1@@ -2228,7 +2228,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 );/* Update own tolerance if peer indicates a non-zero value */ if (tipc_in_range(peers_tol,
TIPC_MIN_LINK_TOL,TIPC_MAX_LINK_TOL)) { diff --gita/net/tipc/node.cb/net/tipc/node.cindexccf5e427f43e..cb43f2016a70100644net/tipc/node.c +1
-1@@ -1581,7 +1581,7 @@ int tipc_node_get_linkname(struct net *net, u32 bearer_id, u32 addr,tipc_node_read_lock (node); link = node->links[bearer_id].link;if (link) { -strncpy (linkname,tipc_link_name (link), len); +strscpy (linkname,tipc_link_name (link), len); err =0 ; }tipc_node_read_unlock(node);
Quoted 2 lines
--
2.39.5
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 10 lines · On Fri, 11 Apr 2025 14:20:10 +0530 you wrote:
This patch suggests the replacement of strncpy with strscpy
as perDocumentation/process/deprecated.
Thestrncpy()fails to guarantee NULL termination,
The function adds zero pads which isn't really convenient for short strings as it may cause performance issues.
strscpy()is a preferred replacement because
it overcomes the limitations of strncpy mentioned above.[...]
Here is the summary with links:
- [net-next] tipc: Removing deprecated strncpy()
https://git.kernel.org/netdev/net-next/c/8c9b406ff470
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html