linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs: fuse: Use strscpy instead of strcpy
@ 2025-09-17 20:55 Miquel Sabaté Solà
  2025-09-19  6:43 ` Miklos Szeredi
  0 siblings, 1 reply; 3+ messages in thread
From: Miquel Sabaté Solà @ 2025-09-17 20:55 UTC (permalink / raw)
  To: miklos; +Cc: linux-fsdevel, linux-kernel, Miquel Sabaté Solà

As pointed out in [1], strcpy() is deprecated in favor of
strscpy().

Furthermore, the length of the name to be copied is well known at this
point since we are going to move the pointer by that much on the next
line. Hence, it's safe to assume 'namelen' for the length of the string
to be copied.

[1] KSPP#88

Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
---
 fs/fuse/dir.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index 5c569c3cb53f..4982efa2c178 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -504,7 +504,7 @@ static int get_security_context(struct dentry *entry, umode_t mode,
 		fctx->size = lsmctx.len;
 		ptr += sizeof(*fctx);
 
-		strcpy(ptr, name);
+		strscpy(ptr, name, namelen);
 		ptr += namelen;
 
 		memcpy(ptr, lsmctx.context, lsmctx.len);
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs: fuse: Use strscpy instead of strcpy
  2025-09-17 20:55 [PATCH] fs: fuse: Use strscpy instead of strcpy Miquel Sabaté Solà
@ 2025-09-19  6:43 ` Miklos Szeredi
  2025-09-19  7:54   ` Miquel Sabaté Solà
  0 siblings, 1 reply; 3+ messages in thread
From: Miklos Szeredi @ 2025-09-19  6:43 UTC (permalink / raw)
  To: Miquel Sabaté Solà; +Cc: linux-fsdevel, linux-kernel

On Wed, 17 Sept 2025 at 22:55, Miquel Sabaté Solà <mssola@mssola.com> wrote:
>
> As pointed out in [1], strcpy() is deprecated in favor of
> strscpy().
>
> Furthermore, the length of the name to be copied is well known at this
> point since we are going to move the pointer by that much on the next
> line. Hence, it's safe to assume 'namelen' for the length of the string
> to be copied.

By "length of a string" usually the number of non-null chars is meant
(i.e. strlen(str)).

So the variable 'namelen' is confusingly named, a better one would be namesize.

>
> [1] KSPP#88

I don't understand this notation.

Patch itself looks good.

Thanks,
Miklos

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs: fuse: Use strscpy instead of strcpy
  2025-09-19  6:43 ` Miklos Szeredi
@ 2025-09-19  7:54   ` Miquel Sabaté Solà
  0 siblings, 0 replies; 3+ messages in thread
From: Miquel Sabaté Solà @ 2025-09-19  7:54 UTC (permalink / raw)
  To: Miklos Szeredi; +Cc: linux-fsdevel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1297 bytes --]

Hello,

Miklos Szeredi @ 2025-09-19 08:43 +02:

> On Wed, 17 Sept 2025 at 22:55, Miquel Sabaté Solà <mssola@mssola.com> wrote:
>>
>> As pointed out in [1], strcpy() is deprecated in favor of
>> strscpy().
>>
>> Furthermore, the length of the name to be copied is well known at this
>> point since we are going to move the pointer by that much on the next
>> line. Hence, it's safe to assume 'namelen' for the length of the string
>> to be copied.
>
> By "length of a string" usually the number of non-null chars is meant
> (i.e. strlen(str)).
>
> So the variable 'namelen' is confusingly named, a better one would be namesize.

That's a good point. If you want I can add a commit renaming this
variable for v2.

>
>>
>> [1] KSPP#88
>
> I don't understand this notation.

This is because it refers to an issue on Github that is tracking the
effort to move away from strcpy in favor of strscpy. I've seen many
commits tracked there that followed this notation and thus I thought
that was the right thing. Anyways, if you want I can transform this
into a Link tag:

Link: https://github.com/KSPP/linux/issues/88

Or otherwise reference it in any other way you feel is more appropiate.

>
> Patch itself looks good.
>
> Thanks,
> Miklos

Thanks,
Miquel

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 897 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-09-19  7:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-17 20:55 [PATCH] fs: fuse: Use strscpy instead of strcpy Miquel Sabaté Solà
2025-09-19  6:43 ` Miklos Szeredi
2025-09-19  7:54   ` Miquel Sabaté Solà

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).