bcachefs: Replace strlcpy() with strscpy()
PATCH 1/1 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.
Cc Kent Overstreet <[email protected]>
Cc Brian Foster <[email protected]>
Signed-off-by Kees Cook <[email protected]>
--- fs/bcachefs/super.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/bcachefs/super.c +2 -2
@@ -1386,8 +1386,8 @@ static int bch2_dev_attach_bdev(struct bch_fs *c, struct bch_sb_handle *sb)prt_bdevname (&name, ca->disk_sb.bdev);if (c->sb.nr_devices ==1 ) -strlcpy (c->name, name.buf,sizeof (c->name)); -strlcpy (ca->name, name.buf,sizeof (ca->name)); +strscpy (c->name, name.buf,sizeof (c->name)); +strscpy (ca->name, name.buf,sizeof (ca->name));printbuf_exit (&name);
Signature · 1 line
2.34.1