Skip to content

Commit e28b035

Browse files
committed
bcachefs: Replace strlcpy() with strscpy()
strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated[1]. Additionally, it returns the size of the source string, not the resulting size of the destination string. In an effort to remove strlcpy() completely[2], replace strlcpy() here with strscpy(). Nothing checks the return value here, so a direct replacement with strspy() is possible. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy [1] Link: KSPP#89 [2] Cc: Kent Overstreet <kent.overstreet@linux.dev> Cc: Brian Foster <bfoster@redhat.com> Cc: <linux-bcachefs@vger.kernel.org> Link: https://lore.kernel.org/r/20240110235438.work.385-kees@kernel.org Signed-off-by: Kees Cook <keescook@chromium.org>
1 parent b0d326d commit e28b035

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/bcachefs/super.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,8 +1386,8 @@ static int bch2_dev_attach_bdev(struct bch_fs *c, struct bch_sb_handle *sb)
13861386
prt_bdevname(&name, ca->disk_sb.bdev);
13871387

13881388
if (c->sb.nr_devices == 1)
1389-
strlcpy(c->name, name.buf, sizeof(c->name));
1390-
strlcpy(ca->name, name.buf, sizeof(ca->name));
1389+
strscpy(c->name, name.buf, sizeof(c->name));
1390+
strscpy(ca->name, name.buf, sizeof(ca->name));
13911391

13921392
printbuf_exit(&name);
13931393

0 commit comments

Comments
 (0)