RE: [PATCH] xfs: replace deprecated strncpy with strscpy_pad

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Kees Cook
> Sent: 11 April 2024 16:32
> 
> On Wed, Apr 10, 2024 at 01:45:21PM -0700, Justin Stitt wrote:
> > On Tue, Apr 9, 2024 at 9:22 AM Kees Cook <keescook@xxxxxxxxxxxx> wrote:
> > > >
> > > > -     /* 1 larger than sb_fname, so this ensures a trailing NUL char */
> > > > -     memset(label, 0, sizeof(label));
> > > >       spin_lock(&mp->m_sb_lock);
> > > > -     strncpy(label, sbp->sb_fname, XFSLABEL_MAX);
> > > > +     strscpy_pad(label, sbp->sb_fname);
> > >
> > > Is sbp->sb_fname itself NUL-terminated? This looks like another case of
> > > needing the memtostr() helper?
> > >
> >
> > I sent a patch [1].
> >
> > Obviously it depends on your implementation patch landing first; what
> > tree should it go to?
> 
> This "flavor" of conversion may need to wait a release? There's no
> urgency on the conversion, and there are plenty more to do for this
> cycle. ;)

In this case:
	char label[sizeof (sbp->fb_fname) + 1];
	memcpy(label, sbp->sb_fname, sizeof (sbp->sb_fname));
	label[sizeof (sbp->fname)] = 0;
is probably the clearest code.
(it is [12] - so no point faffing with the copy.)

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)




[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux