]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tipc: Removing deprecated strncpy()
authorKevin Paul Reddy Janagari <kevinpaul468@gmail.com>
Fri, 11 Apr 2025 08:50:10 +0000 (14:20 +0530)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 15 Apr 2025 11:37:14 +0000 (13:37 +0200)
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>
Reviewed-by: Tung Nguyen <tung.quang.nguyen@est.tech>
Tested-by: Tung Nguyen <tung.quang.nguyen@est.tech>
Link: https://patch.msgid.link/20250411085010.6249-1-kevinpaul468@gmail.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
net/tipc/link.c
net/tipc/node.c

index 18be6ff4c3db0ac80d5770032859244177ae12c7..3ee44d73170041d7cb470bf625956b867b25bae5 100644 (file)
@@ -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)) {
index ccf5e427f43ebcfc033b7e6e3be71b1d451328ae..cb43f2016a708471e8047b00a8f7ab4c532339c7 100644 (file)
@@ -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);