diff mbox series

nfs_sysfs_link_rpc_client(): Replace strcpy with strscpy

Message ID 20241106024952.494718-1-danielyangkang@gmail.com (mailing list archive)
State New
Headers show
Series nfs_sysfs_link_rpc_client(): Replace strcpy with strscpy | expand

Commit Message

Daniel Yang Nov. 6, 2024, 2:49 a.m. UTC
The function strcpy is deprecated due to lack of bounds checking. The
recommended replacement is strscpy.

Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
---
 fs/nfs/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Benjamin Coddington Nov. 6, 2024, 7:30 p.m. UTC | #1
On 5 Nov 2024, at 21:49, Daniel Yang wrote:

> The function strcpy is deprecated due to lack of bounds checking. The
> recommended replacement is strscpy.
>
> Signed-off-by: Daniel Yang <danielyangkang@gmail.com>

Reviewed-by: Benjamin Coddington <bcodding@redhat.com>

Ben
Roland Mainz Nov. 6, 2024, 8:20 p.m. UTC | #2
On Wed, Nov 6, 2024 at 3:49 AM Daniel Yang <danielyangkang@gmail.com> wrote:
>
> The function strcpy is deprecated due to lack of bounds checking. The
> recommended replacement is strscpy.
>
> Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
> ---
>  fs/nfs/sysfs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
> index bf378ecd5..f3d0b2ef9 100644
> --- a/fs/nfs/sysfs.c
> +++ b/fs/nfs/sysfs.c
> @@ -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
Benjamin Coddington Nov. 6, 2024, 8:40 p.m. UTC | #3
On 6 Nov 2024, at 15:20, Roland Mainz wrote:

> On Wed, Nov 6, 2024 at 3:49 AM Daniel Yang <danielyangkang@gmail.com> wrote:
>>
>> The function strcpy is deprecated due to lack of bounds checking. The
>> recommended replacement is strscpy.
>>
>> Signed-off-by: Daniel Yang <danielyangkang@gmail.com>
>> ---
>>  fs/nfs/sysfs.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
>> index bf378ecd5..f3d0b2ef9 100644
>> --- a/fs/nfs/sysfs.c
>> +++ b/fs/nfs/sysfs.c
>> @@ -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 ?

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

Ben
diff mbox series

Patch

diff --git a/fs/nfs/sysfs.c b/fs/nfs/sysfs.c
index bf378ecd5..f3d0b2ef9 100644
--- a/fs/nfs/sysfs.c
+++ b/fs/nfs/sysfs.c
@@ -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");