From: David Laight <david.laight.linux@gmail.com>
To: Mariia Nikitash <mariianikitash@google.com>
Cc: trondmy@kernel.org, anna@kernel.org, keescook@google.com,
justinstitt@google.com, linux-hardening@vger.kernel.org,
linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
nikitash.mariiaw@gmail.com
Subject: Re: [PATCH] NFS: nfsroot: replace strlcat() with snprintf()
Date: Tue, 18 Aug 2026 09:55:48 +0100 [thread overview]
Message-ID: <20260818095548.27e0edb2@pumpkin> (raw)
In-Reply-To: <27956255dde39f58d73a7b51cb53cbe3d7804f54.1786411026.git.mariianikitash@google.com>
On Fri, 14 Aug 2026 00:28:45 -0700
Mariia Nikitash <mariianikitash@google.com> wrote:
> In preparation for removing the deprecated strlcat() API[1], replace its
> uses in root_nfs_cat() with snprintf().
>
> Build the separator and source string in a single call using the
> remaining space in the destination buffer. snprintf() returns the length
> it would have written excluding the terminating NUL, so comparing the
> return value against the remaining buffer space preserves the existing
> truncation check.
>
> Link: https://github.com/KSPP/linux/issues/370 [1]
> Signed-off-by: Mariia Nikitash <mariianikitash@google.com>
> ---
> fs/nfs/nfsroot.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/fs/nfs/nfsroot.c b/fs/nfs/nfsroot.c
> index 432612d22437..e951fe731679 100644
> --- a/fs/nfs/nfsroot.c
> +++ b/fs/nfs/nfsroot.c
> @@ -173,12 +173,12 @@ static int __init root_nfs_cat(char *dest, const char *src,
> const size_t destlen)
> {
> size_t len = strlen(dest);
> + size_t remaining = destlen - len;
> + const char *sep = "";
>
> if (len && dest[len - 1] != ',')
> - if (strlcat(dest, ",", destlen) >= destlen)
> - return -1;
> -
> - if (strlcat(dest, src, destlen) >= destlen)
> + sep = ",";
> + if (snprintf(dest + len, remaining, "%s%s", sep, src) >= remaining)
> return -1;
I think I'd have gone for:
size_t len = strlen(dest);
if (len && dest[len - 1] != ',' && ++len < destlen)
dest[len - 1] = ',';
if (strscpy(dest + len, src, destlen - len) < 0)
return -1;
Although it would be better as an 'add_option()' function.
I suspect the it used to be just strcat().
(similarly for root_nfs_copy() which is a pointless wrapper on strscpy()).
Much more worth while would be fixing the sprintf() for NFS_ROOT.
David
> return 0;
> }
next prev parent reply other threads:[~2026-08-18 8:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-14 7:28 [PATCH] NFS: nfsroot: replace strlcat() with snprintf() Mariia Nikitash
2026-08-17 20:33 ` Justin Stitt
2026-08-17 20:51 ` Bill Wendling
2026-08-18 8:55 ` David Laight [this message]
2026-08-18 17:42 ` Kees Cook
2026-08-18 18:44 ` Mariia Nikitash
2026-08-18 21:05 ` Justin Stitt
2026-08-19 10:22 ` David Laight
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260818095548.27e0edb2@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=anna@kernel.org \
--cc=justinstitt@google.com \
--cc=keescook@google.com \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=mariianikitash@google.com \
--cc=nikitash.mariiaw@gmail.com \
--cc=trondmy@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.