On Mon Jun 8, 2026 at 5:55 PM CST, david.laight.linux wrote: > From: David Laight <[email protected]> > > Replace strcpy() with strscpy() and sprintf() with snprintf() for safety. > > Signed-off-by: David Laight <[email protected]> > --- > This is one of a group of patches that remove potentially unbounded > strcpy() calls. > > They are mostly replaced by strscpy() or, when strlen() has just been > called, with memcpy() (usually including the '\0'). > > Calls with copy string literals into arrays are left unchanged. > They are safe and easily detected as such. > > The changes were made by getting the compiler to detect the calls and > then fixing the code by hand. > > Note that all the changes are only compile tested. > > Some Makefiles were changed to allow files to contain strcpy(). > As well as 'difficult to fix' files, this included 'show' functions > as they really need to use sysfs_emit() or seq_printf(). > > All the patches are being sent individually to avoid very long cc lists. > Apologies for the terse commit messages and likely unexpected tags. > (There are about 100 patches in total.) > > drivers/md/md.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/md/md.c b/drivers/md/md.c > index 8b568eee8743..4b659d10fa4d 100644 > --- a/drivers/md/md.c > +++ b/drivers/md/md.c > @@ -6346,11 +6346,11 @@ struct mddev *md_alloc(dev_t dev, char *name) > disk->first_minor = unit << shift; > disk->minors = 1 << shift; > if (name) > - strcpy(disk->disk_name, name); > + strscpy(disk->disk_name, name); > else if (partitioned) > - sprintf(disk->disk_name, "md_d%d", unit); > + snprintf(disk->disk_name, sizeof (disk->disk_name), "md_d%d", > unit);
Please remove the space after sizeof to match the style used elsewhere in this file. > else > - sprintf(disk->disk_name, "md%d", unit); > + snprintf(disk->disk_name, sizeof (disk->disk_name), "md%d", > unit); > disk->fops = &md_fops; > disk->private_data = mddev; > -- Thanks, Nan

