[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAH4c4j+N0OrdmeeEUALKE+fQpVZjWNHegFMPTq2DmotSmBtsdw@mail.gmail.com>
Date: Tue, 1 Jul 2025 21:12:07 +0530
From: Pranav Tyagi <pranav.tyagi03@...il.com>
To: "Darrick J. Wong" <djwong@...nel.org>
Cc: Brahmajit Das <listout@...tout.xyz>, Carlos Maiolino <cem@...nel.org>, skhan@...uxfoundation.org,
linux-kernel-mentees@...ts.linux.dev, linux-xfs@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] fs/xfs: replace strncpy with strscpy
On Tue, Jul 1, 2025 at 8:27 PM Darrick J. Wong <djwong@...nel.org> wrote:
>
> On Tue, Jul 01, 2025 at 02:18:12PM +0530, Pranav Tyagi wrote:
> > On Mon, Jun 30, 2025 at 7:48 PM Brahmajit Das <listout@...tout.xyz> wrote:
> > >
> > > On 30.06.2025 14:36, Pranav Tyagi wrote:
> > > ... snip ...
> > > > > > spin_unlock(&mp->m_sb_lock);
> > > > > >
> > > > > > if (copy_to_user(user_label, label, sizeof(label)))
> > > > > > --
> > > > > > 2.49.0
> > > > > >
> > > >
> > > > Hi,
> > > >
> > > > Thank you for the feedback. I understand that my patch is incorrect and
> > > > it causes a buffer overrun. The destination buffer is indeed, already, null
> > > > terminated. Would you like me to send a corrected patch which uses
> > > > strscpy() (as strncpy() is deprecated)?
> > > >
> > > If the destination buffer is already NUL terminated, you can use either
> > > strtomem or strtomem_pad [0].
> > >
> > > [0]: https://docs.kernel.org/core-api/kernel-api.html#c.strncpy
> > > (Description)
> >
> > Thank you for the suggestion. On going through [0], I see that,
> > both, strtomem and strscpy require the src to be null
> > terminated. As far as I know, sb_fname buffer has a size of
> > XFSLABEL_MAX (12 bytes). This means no terminating NULL
> > for the src. So shouldn't memcpy() be the right function to use here?
>
> memtostr_pad?
>
> --D
>
Thanks for the suggestion. memtostr_pad fits perfectly for this use case.
It takes care of null termination as well as avoids the need for separate
zeroing. I'll update the patch accordingly and resend it.
Regards
Pranav Tyagi
> > > > Regret the inconvenience.
> > > >
> > > > Regards
> > > > Pranav Tyagi
> > > >
> > >
> > > --
> > > Regards,
> > > listout
> >
Powered by blists - more mailing lists