All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thorsten Blum <thorsten.blum@linux.dev>
To: David Howells <dhowells@redhat.com>,
	Marc Dionne <marc.dionne@auristor.com>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
	linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH RESEND 1/2] afs: replace deprecated strcpy with strscpy in afs_lookup_atsys
Date: Fri,  8 May 2026 16:43:28 +0200	[thread overview]
Message-ID: <20260508144326.3566-4-thorsten.blum@linux.dev> (raw)

strcpy() has been deprecated [1] because it performs no bounds checking
on the destination buffer, which can lead to buffer overflows. Replace
it with the safer strscpy(), drop the manual length check and the
now-unused local length variable.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 fs/afs/dir.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index aaaa55878ffd..24cea4d7eadf 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -9,6 +9,7 @@
 #include <linux/fs.h>
 #include <linux/namei.h>
 #include <linux/pagemap.h>
+#include <linux/string.h>
 #include <linux/swap.h>
 #include <linux/ctype.h>
 #include <linux/sched.h>
@@ -914,7 +915,7 @@ static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry)
 	struct afs_net *net = afs_i2net(dir);
 	struct dentry *ret;
 	char *buf, *p, *name;
-	int len, i;
+	int i;
 
 	_enter("");
 
@@ -935,13 +936,11 @@ static struct dentry *afs_lookup_atsys(struct inode *dir, struct dentry *dentry)
 
 	for (i = 0; i < subs->nr; i++) {
 		name = subs->subs[i];
-		len = dentry->d_name.len - 4 + strlen(name);
-		if (len >= AFSNAMEMAX) {
+		if (strscpy(p, name, AFSNAMEMAX - (p - buf)) < 0) {
 			ret = ERR_PTR(-ENAMETOOLONG);
 			goto out_s;
 		}
 
-		strcpy(p, name);
 		ret = lookup_noperm(&QSTR(buf), dentry->d_parent);
 		if (IS_ERR(ret) || d_is_positive(ret))
 			goto out_s;

             reply	other threads:[~2026-05-08 14:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-08 14:43 Thorsten Blum [this message]
2026-05-08 14:43 ` [PATCH RESEND 2/2] afs: replace goto with direct return in afs_lookup_atsys Thorsten Blum
  -- strict thread matches above, loose matches on Subject: below --
2026-06-06 21:23 [PATCH RESEND 1/2] afs: replace deprecated strcpy with strscpy " Thorsten Blum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260508144326.3566-4-thorsten.blum@linux.dev \
    --to=thorsten.blum@linux.dev \
    --cc=dhowells@redhat.com \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marc.dionne@auristor.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.