diff mbox series

Removing deprecated strncpy()

Message ID 20250410123250.64993-1-kevinpaul468@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series Removing deprecated strncpy() | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 3 this patch: 3
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2025-04-11--00-00 (tests: 900)

Commit Message

Kevin Paul Reddy Janagari April 10, 2025, 12:32 p.m. UTC
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(-)

Comments

Tung Nguyen April 11, 2025, 1:10 a.m. UTC | #1
>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.
>
>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);
Could you please do the same replacement in function tipc_node_get_linkname() (node.c) ?

>
> 		/* 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
>
Kevin Paul Reddy Janagari April 11, 2025, 5:12 a.m. UTC | #2
https://lore.kernel.org/all/20250411050613.10550-1-kevinpaul468@gmail.com

Reguards
kevin
diff mbox series

Patch

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)) {