[PATCH 1/2] afs: replace deprecated strcpy with strscpy in afs_lookup_atsys
Thorsten Blum
thorsten.blum at linux.dev
Tue Mar 24 08:45:16 PDT 2026
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.
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
Signed-off-by: Thorsten Blum <thorsten.blum at 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 78caef3f1338..89d5c9c354d4 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;
More information about the linux-afs
mailing list