Skip to contentSkip to conversation

nfs_sysfs_link_rpc_client(): Replace strcpy with strscpy

PATCH In review Daniel Yang 5 participants 7 messages Nov 6, 2024 – Nov 9, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfs_sysfs_link_rpc_client(): Replace strcpy with strscpy

The function strcpy is deprecated due to lack of bounds checking. The recommended replacement is strscpy.

---
 fs/nfs/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/sysfs.c +1 -1
index bf378ecd5..f3d0b2ef9 100644
@@ -280,7 +280,7 @@ void nfs_sysfs_link_rpc_client(struct nfs_server *server,
 	char name[RPC_CLIENT_NAME_SIZE];
 	int ret;
 
-	strcpy(name, clnt->cl_program->name);
+	strscpy(name, clnt->cl_program->name);
 	strcat(name, uniq ? uniq : "");
 	strcat(name, "_client");
 
Signature · 1 line
2.39.5
#2 lore raw
In reply to Daniel Yang
Quoted 14 lines · Daniel Yang

The function strcpy is deprecated due to lack of bounds checking. The recommended replacement is strscpy.

---
 fs/nfs/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/sysfs.c +0 -0
index bf378ecd5..f3d0b2ef9 100644

fs/nfs/sysfs.c void nfs_sysfs_link_rpc_client(struct nfs_server *server, · line 283

Quoted 5 lines
fs/nfs/sysfs.c +1 -1
@@ -280,7 +280,7 @@ void nfs_sysfs_link_rpc_client(struct nfs_server *server,
        char name[RPC_CLIENT_NAME_SIZE];
        int ret;
 
-       strcpy(name, clnt->cl_program->name);
+       strscpy(name, clnt->cl_program->name);

How should the "bounds checking" work in this case if you only pass two arguments ?
Per https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html
|strscpy()| takes three arguments...

----

Bye,
Roland

Signature · 5 lines
  __ .  . __
 (o.\ \/ /.o) [email protected]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)
#3 lore raw
Quoted 18 lines · Roland Mainz
Quoted 17 lines · Daniel Yang

The function strcpy is deprecated due to lack of bounds checking. The recommended replacement is strscpy.

---
 fs/nfs/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/sysfs.c +0 -0
index bf378ecd5..f3d0b2ef9 100644
@@ -280,7 +280,7 @@ void nfs_sysfs_link_rpc_client(struct nfs_server *server,
        char name[RPC_CLIENT_NAME_SIZE];
        int ret;
 
Quoted 5 lines

fs/nfs/sysfs.c void nfs_sysfs_link_rpc_client(struct nfs_server *server, · line 283

Quoted 2 lines
fs/nfs/sysfs.c +1 -1
-       strcpy(name, clnt->cl_program->name);
+       strscpy(name, clnt->cl_program->name);

How should the "bounds checking" work in this case if you only pass two arguments ?

The linux kernel strscpy() checks the sizeof the destination.

Ben

#4 lore raw

Kernel strscpy() should be renamed to kstrscpy() Re: [PATCH] nfs_sysfs_link_rpc_client(): Replace strcpy with strscpy

Quoted 21 lines · Benjamin Coddington
Quoted 18 lines · Roland Mainz
Quoted 17 lines · Daniel Yang

The function strcpy is deprecated due to lack of bounds checking. The recommended replacement is strscpy.

---
 fs/nfs/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/sysfs.c +0 -0
index bf378ecd5..f3d0b2ef9 100644
@@ -280,7 +280,7 @@ void nfs_sysfs_link_rpc_client(struct nfs_server *server,
        char name[RPC_CLIENT_NAME_SIZE];
        int ret;
 
Quoted 7 lines
Quoted 5 lines

fs/nfs/sysfs.c void nfs_sysfs_link_rpc_client(struct nfs_server *server, · line 283

Quoted 2 lines
fs/nfs/sysfs.c +1 -1
-       strcpy(name, clnt->cl_program->name);
+       strscpy(name, clnt->cl_program->name);

How should the "bounds checking" work in this case if you only pass two arguments ?

The linux kernel strscpy() checks the sizeof the destination.

Then the kernel strscpy() should be renamed accordingly, and not confuse people. Suggested name would be kstrscpy(). Otherwise this would disqualify strscpy() ever from being adopted as a POSIX standard, as there are two - kernel and glibc - conflicting implementations

Sebi

Signature · 1 line
Sebastian Feld - IT secruity expert
#5 lore raw

Re: Kernel strscpy() should be renamed to kstrscpy() Re: [PATCH] nfs_sysfs_link_rpc_client(): Replace strcpy with strscpy

Quoted 28 lines · Sebastian Feld
Quoted 27 lines · Benjamin Coddington
Quoted 23 lines · Roland Mainz
Quoted 14 lines · Daniel Yang

The function strcpy is deprecated due to lack of bounds checking. The recommended replacement is strscpy.

---
 fs/nfs/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/sysfs.c +0 -0
index bf378ecd5..f3d0b2ef9 100644

fs/nfs/sysfs.c void nfs_sysfs_link_rpc_client(struct nfs_server *server, · line 283

Quoted 5 lines
fs/nfs/sysfs.c +1 -1
@@ -280,7 +280,7 @@ void nfs_sysfs_link_rpc_client(struct nfs_server *server,
        char name[RPC_CLIENT_NAME_SIZE];
        int ret;
 
-       strcpy(name, clnt->cl_program->name);
+       strscpy(name, clnt->cl_program->name);

How should the "bounds checking" work in this case if you only pass two arguments ?

Quoted 7 lines
Quoted 1 line

The linux kernel strscpy() checks the sizeof the destination.

Then the kernel strscpy() should be renamed accordingly, and not confuse people. Suggested name would be kstrscpy(). Otherwise this would disqualify strscpy() ever from being adopted as a POSIX standard, as there are two - kernel and glibc - conflicting implementations

I should have said the linux kernel strscpy() can accept only two args if the destination is a statically-defined array. Most uses are the three arg version.

Ben

#6 lore raw

Re: Kernel strscpy() should be renamed to kstrscpy() Re: [PATCH] nfs_sysfs_link_rpc_client(): Replace strcpy with strscpy

In reply to Sebastian Feld
Quoted 10 lines · Sebastian Feld
Quoted 4 lines
Quoted 2 lines

How should the "bounds checking" work in this case if you only pass two arguments ?

The linux kernel strscpy() checks the sizeof the destination.

Then the kernel strscpy() should be renamed accordingly, and not confuse people. Suggested name would be kstrscpy(). Otherwise this would disqualify strscpy() ever from being adopted as a POSIX standard, as there are two - kernel and glibc - conflicting implementations

If POSIX decided that this meant they couldn't adopt strscpy(), that is ANSI / ISO's problem, not ours. Note that strscpy() supports the 3 argument version of glibc, and POSIX has always been willing to standardize a subset of a particullar interface.

Otherwise, any Legacy Unix system which added some one or more flags to some particular interface could potentially disqualify anything with the same name of that interface from ever being standardized, which is (a) stupid, and (b) not what has been done in historical practice.

- Ted