Skip to contentSkip to conversation

net: tipc: replace deprecated strcpy with strscpy

PATCH Superseded Ajith P V 2 participants 3 messages Aug 11 – Aug 12

Subsystems (3)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Ajith P V

author
#0 lore raw

PATCH 1/1 net: tipc: replace deprecated strcpy with strscpy

The strcpy() function is deprecated and moving towards code-tree elimination. Replacing it with strscpy() fixes potential buffer overflow vectors by ensuring safe NULL-termination based on the destination buffer size limit [1][2].

In tipc_bearer_get_name(), the 'name' parameter decays into a pointer, meaning sizeof() cannot capture the underlying array bounds directly. However, all parent callers allocate this buffer using the TIPC_MAX_BEARER_NAME macro.

Replace strcpy() with strscpy() using TIPC_MAX_BEARER_NAME as the explicit destination bound length.

---
 net/tipc/bearer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/tipc/bearer.c +1 -1
index 05dcd2f9e887..951bb474c7d4 100644
@@ -209,7 +209,7 @@ int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id)
 	if (!b)
 		return -EINVAL;
 
-	strcpy(name, b->name);
+	strscpy(name, b->name, TIPC_MAX_BEARER_NAME);
 	return 0;
 }
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 1 line

Subject: [PATCH] net: tipc: replace deprecated strcpy with strscpy

Please fix the target tree name.
Since this patch is just an improvement, the tree name should be "[PATCH net-next]".

Quoted 40 lines

The strcpy() function is deprecated and moving towards code-tree elimination. Replacing it with strscpy() fixes potential buffer overflow vectors by ensuring safe NULL-termination based on the destination buffer size limit [1][2].

In tipc_bearer_get_name(), the 'name' parameter decays into a pointer, meaning sizeof() cannot capture the underlying array bounds directly. However, all parent callers allocate this buffer using the TIPC_MAX_BEARER_NAME macro.

Replace strcpy() with strscpy() using TIPC_MAX_BEARER_NAME as the explicit destination bound length.

---
net/tipc/bearer.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
net/tipc/bearer.c index renamed from net/tipc/bearer.c +0 -0

05dcd2f9e887..951bb474c7d4 100644

net/tipc/bearer.c +1 -2
@@ -209,7 +209,7 @@ int tipc_bearer_get_name(struct net *net, char *name,
 u32 bearer_id)
 	if (!b)
 		return -EINVAL;
 
-	strcpy(name, b->name);
+	strscpy(name, b->name, TIPC_MAX_BEARER_NAME);
 	return 0;
 }
 
--

2.43.0

author
#2 lore raw

PATCH v2 1/1 net: tipc: replace deprecated strcpy with strscpy

The strcpy() function is deprecated and moving towards code-tree elimination. Replacing it with strscpy() fixes potential buffer overflow vectors by ensuring safe NULL-termination based on the destination buffer size limit [1][2].

In tipc_bearer_get_name(), the 'name' parameter decays into a pointer, meaning sizeof() cannot capture the underlying array bounds directly. However, all parent callers allocate this buffer using the TIPC_MAX_BEARER_NAME macro.

Replace strcpy() with strscpy() using TIPC_MAX_BEARER_NAME as the explicit destination bound length.

---
v2:
- Target net-next tree instead of standard net tree as requested by Tung Quang Nguyen.
- No code changes from v1.

 net/tipc/bearer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/tipc/bearer.c +1 -1
index 05dcd2f9e887..951bb474c7d4 100644
@@ -209,7 +209,7 @@ int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id)
 	if (!b)
 		return -EINVAL;
 
-	strcpy(name, b->name);
+	strscpy(name, b->name, TIPC_MAX_BEARER_NAME);
 	return 0;
 }
 
Signature · 1 line
2.43.0