* [PATCH net-next] tipc: Removing deprecated strncpy()
@ 2025-04-11 8:50 Kevin Paul Reddy Janagari
2025-04-11 10:46 ` Tung Quang Nguyen
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Kevin Paul Reddy Janagari @ 2025-04-11 8:50 UTC (permalink / raw)
To: jmaloy, davem, edumazet, kuba, pabeni, horms, netdev,
tipc-discussion, linux-kernel, tung.quang.nguyen, kevinpaul468
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
Signed-off-by: Kevin Paul Reddy Janagari <kevinpaul468@gmail.com>
---
net/tipc/link.c | 2 +-
net/tipc/node.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/tipc/link.c b/net/tipc/link.c
index 18be6ff4c3db..3ee44d731700 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -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)) {
diff --git a/net/tipc/node.c b/net/tipc/node.c
index ccf5e427f43e..cb43f2016a70 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -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);
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* RE: [PATCH net-next] tipc: Removing deprecated strncpy()
2025-04-11 8:50 [PATCH net-next] tipc: Removing deprecated strncpy() Kevin Paul Reddy Janagari
@ 2025-04-11 10:46 ` Tung Quang Nguyen
2025-04-14 19:25 ` Simon Horman
2025-04-15 1:36 ` Tung Quang Nguyen
2025-04-15 11:40 ` patchwork-bot+netdevbpf
2 siblings, 1 reply; 5+ messages in thread
From: Tung Quang Nguyen @ 2025-04-11 10:46 UTC (permalink / raw)
To: Kevin Paul Reddy Janagari, jmaloy@redhat.com, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
horms@kernel.org, netdev@vger.kernel.org,
tipc-discussion@lists.sourceforge.net,
linux-kernel@vger.kernel.org
>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
>
>Signed-off-by: Kevin Paul Reddy Janagari <kevinpaul468@gmail.com>
>---
> net/tipc/link.c | 2 +-
> net/tipc/node.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/net/tipc/link.c b/net/tipc/link.c index 18be6ff4c3db..3ee44d731700
>100644
>--- a/net/tipc/link.c
>+++ b/net/tipc/link.c
>@@ -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)) { diff --git a/net/tipc/node.c b/net/tipc/node.c index
>ccf5e427f43e..cb43f2016a70 100644
>--- a/net/tipc/node.c
>+++ b/net/tipc/node.c
>@@ -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);
>--
>2.39.5
Reviewed-and-tested-by: Tung Nguyen <tung.quang.nguyen@est.tech>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] tipc: Removing deprecated strncpy()
2025-04-11 10:46 ` Tung Quang Nguyen
@ 2025-04-14 19:25 ` Simon Horman
0 siblings, 0 replies; 5+ messages in thread
From: Simon Horman @ 2025-04-14 19:25 UTC (permalink / raw)
To: Tung Quang Nguyen
Cc: Kevin Paul Reddy Janagari, jmaloy, davem, edumazet, kuba, pabeni,
netdev, tipc-discussion, linux-kernel
On Fri, Apr 11, 2025 at 10:46:32AM +0000, Tung Quang Nguyen wrote:
> >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
> >
> >Signed-off-by: Kevin Paul Reddy Janagari <kevinpaul468@gmail.com>
> >---
> > net/tipc/link.c | 2 +-
> > net/tipc/node.c | 2 +-
> > 2 files changed, 2 insertions(+), 2 deletions(-)
> >
> >diff --git a/net/tipc/link.c b/net/tipc/link.c index 18be6ff4c3db..3ee44d731700
> >100644
> >--- a/net/tipc/link.c
> >+++ b/net/tipc/link.c
> >@@ -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)) { diff --git a/net/tipc/node.c b/net/tipc/node.c index
> >ccf5e427f43e..cb43f2016a70 100644
> >--- a/net/tipc/node.c
> >+++ b/net/tipc/node.c
> >@@ -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);
> >--
> >2.39.5
> Reviewed-and-tested-by: Tung Nguyen <tung.quang.nguyen@est.tech>
Hi Tung,
Thanks for reviewing these patches,
but I think it's best not to use non-standard tags.
Reviewed-by: ...
Tested-by: ...
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH net-next] tipc: Removing deprecated strncpy()
2025-04-11 8:50 [PATCH net-next] tipc: Removing deprecated strncpy() Kevin Paul Reddy Janagari
2025-04-11 10:46 ` Tung Quang Nguyen
@ 2025-04-15 1:36 ` Tung Quang Nguyen
2025-04-15 11:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: Tung Quang Nguyen @ 2025-04-15 1:36 UTC (permalink / raw)
To: Kevin Paul Reddy Janagari, jmaloy@redhat.com, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
horms@kernel.org, netdev@vger.kernel.org,
tipc-discussion@lists.sourceforge.net,
linux-kernel@vger.kernel.org, Simon Horman
>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
>
>Signed-off-by: Kevin Paul Reddy Janagari <kevinpaul468@gmail.com>
>---
> net/tipc/link.c | 2 +-
> net/tipc/node.c | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/net/tipc/link.c b/net/tipc/link.c index 18be6ff4c3db..3ee44d731700
>100644
>--- a/net/tipc/link.c
>+++ b/net/tipc/link.c
>@@ -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)) { diff --git a/net/tipc/node.c b/net/tipc/node.c index
>ccf5e427f43e..cb43f2016a70 100644
>--- a/net/tipc/node.c
>+++ b/net/tipc/node.c
>@@ -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);
>--
>2.39.5
Reviewed-by: Tung Nguyen <tung.quang.nguyen@est.tech>
Tested-by: Tung Nguyen <tung.quang.nguyen@est.tech>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] tipc: Removing deprecated strncpy()
2025-04-11 8:50 [PATCH net-next] tipc: Removing deprecated strncpy() Kevin Paul Reddy Janagari
2025-04-11 10:46 ` Tung Quang Nguyen
2025-04-15 1:36 ` Tung Quang Nguyen
@ 2025-04-15 11:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-04-15 11:40 UTC (permalink / raw)
To: Kevin Paul Reddy Janagari
Cc: jmaloy, davem, edumazet, kuba, pabeni, horms, netdev,
tipc-discussion, linux-kernel, tung.quang.nguyen
Hello:
This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Fri, 11 Apr 2025 14:20:10 +0530 you wrote:
> 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.
>
> [...]
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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-04-15 11:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-11 8:50 [PATCH net-next] tipc: Removing deprecated strncpy() Kevin Paul Reddy Janagari
2025-04-11 10:46 ` Tung Quang Nguyen
2025-04-14 19:25 ` Simon Horman
2025-04-15 1:36 ` Tung Quang Nguyen
2025-04-15 11:40 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).